home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / resources.pak / Unnamed File 000113.unknown < prev    next >
Text File  |  2013-04-03  |  135KB  |  4,784 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. WebInspector.CSSNamedFlowCollectionsView = function()
  8. {
  9. WebInspector.SidebarView.call(this, WebInspector.SidebarView.SidebarPosition.Left);
  10. this.registerRequiredCSS("cssNamedFlows.css");
  11.  
  12. this._namedFlows = {};
  13. this._contentNodes = {};
  14. this._regionNodes = {};
  15.  
  16. this.element.addStyleClass("css-named-flow-collections-view");
  17. this.element.addStyleClass("fill");
  18.  
  19. this._statusElement = document.createElement("span");
  20. this._statusElement.textContent = WebInspector.UIString("CSS Named Flows");
  21.  
  22. var sidebarHeader = this._leftElement.createChild("div", "tabbed-pane-header selected sidebar-header")
  23. var tab = sidebarHeader.createChild("div", "tabbed-pane-header-tab");
  24. tab.createChild("span", "tabbed-pane-header-tab-title").textContent = WebInspector.UIString("CSS Named Flows");
  25.  
  26. this._sidebarContentElement = this._leftElement.createChild("div", "sidebar-content outline-disclosure");
  27. this._flowListElement = this._sidebarContentElement.createChild("ol");
  28. this._flowTree = new TreeOutline(this._flowListElement);
  29.  
  30. this._emptyElement = document.createElement("div");
  31. this._emptyElement.addStyleClass("info");
  32. this._emptyElement.textContent = WebInspector.UIString("No CSS Named Flows");
  33.  
  34. this._tabbedPane = new WebInspector.TabbedPane();
  35. this._tabbedPane.closeableTabs = true;
  36. this._tabbedPane.show(this._rightElement);
  37. }
  38.  
  39. WebInspector.CSSNamedFlowCollectionsView.prototype = {
  40. showInDrawer: function()
  41. {
  42. WebInspector.showViewInDrawer(this._statusElement, this);
  43. },
  44.  
  45. reset: function()
  46. {
  47. if (!this._document)
  48. return;
  49.  
  50. WebInspector.cssModel.getNamedFlowCollectionAsync(this._document.id, this._resetNamedFlows.bind(this));
  51. },
  52.  
  53.  
  54. _setDocument: function(document)
  55. {
  56. this._document = document;
  57. this.reset();
  58. },
  59.  
  60.  
  61. _documentUpdated: function(event)
  62. {
  63. var document =   (event.data);
  64. this._setDocument(document);
  65. },
  66.  
  67.  
  68. _setSidebarHasContent: function(hasContent)
  69. {
  70. if (hasContent) {
  71. if (!this._emptyElement.parentNode)
  72. return;
  73.  
  74. this._sidebarContentElement.removeChild(this._emptyElement);
  75. this._sidebarContentElement.appendChild(this._flowListElement);
  76. } else {
  77. if (!this._flowListElement.parentNode)
  78. return;
  79.  
  80. this._sidebarContentElement.removeChild(this._flowListElement);
  81. this._sidebarContentElement.appendChild(this._emptyElement);
  82. }
  83. },
  84.  
  85.  
  86. _appendNamedFlow: function(flow)
  87. {
  88. var flowHash = this._hashNamedFlow(flow.documentNodeId, flow.name);
  89. var flowContainer = { flow: flow, flowHash: flowHash };
  90.  
  91. for (var i = 0; i < flow.content.length; ++i)
  92. this._contentNodes[flow.content[i]] = flowHash;
  93. for (var i = 0; i < flow.regions.length; ++i)
  94. this._regionNodes[flow.regions[i].nodeId] = flowHash;
  95.  
  96. var flowTreeItem = new WebInspector.FlowTreeElement(flowContainer);
  97. flowTreeItem.onselect = this._selectNamedFlowTab.bind(this, flowHash);
  98.  
  99. flowContainer.flowTreeItem = flowTreeItem;
  100. this._namedFlows[flowHash] = flowContainer;
  101.  
  102. if (!this._flowTree.children.length)
  103. this._setSidebarHasContent(true);
  104. this._flowTree.appendChild(flowTreeItem);
  105. },
  106.  
  107.  
  108. _removeNamedFlow: function(flowHash)
  109. {
  110. var flowContainer = this._namedFlows[flowHash];
  111.  
  112. if (this._tabbedPane._tabsById[flowHash])
  113. this._tabbedPane.closeTab(flowHash);
  114. this._flowTree.removeChild(flowContainer.flowTreeItem);
  115.  
  116. var flow = flowContainer.flow;
  117. for (var i = 0; i < flow.content.length; ++i)
  118. delete this._contentNodes[flow.content[i]];
  119. for (var i = 0; i < flow.regions.length; ++i)
  120. delete this._regionNodes[flow.regions[i].nodeId];
  121.  
  122. delete this._namedFlows[flowHash];
  123.  
  124. if (!this._flowTree.children.length)
  125. this._setSidebarHasContent(false);
  126. },
  127.  
  128.  
  129. _updateNamedFlow: function(flow)
  130. {
  131. var flowHash = this._hashNamedFlow(flow.documentNodeId, flow.name);
  132. var flowContainer = this._namedFlows[flowHash];
  133.  
  134. if (!flowContainer)
  135. return;
  136.  
  137. var oldFlow = flowContainer.flow;
  138. flowContainer.flow = flow;
  139.  
  140. for (var i = 0; i < oldFlow.content.length; ++i)
  141. delete this._contentNodes[oldFlow.content[i]];
  142. for (var i = 0; i < oldFlow.regions.length; ++i)
  143. delete this._regionNodes[oldFlow.regions[i].nodeId];
  144.  
  145. for (var i = 0; i < flow.content.length; ++i)
  146. this._contentNodes[flow.content[i]] = flowHash;
  147. for (var i = 0; i < flow.regions.length; ++i)
  148. this._regionNodes[flow.regions[i].nodeId] = flowHash;
  149.  
  150. flowContainer.flowTreeItem.setOverset(flow.overset);
  151.  
  152. if (flowContainer.flowView)
  153. flowContainer.flowView.flow = flow;
  154. },
  155.  
  156.  
  157. _resetNamedFlows: function(namedFlowCollection)
  158. {
  159. for (var flowHash in this._namedFlows)
  160. this._removeNamedFlow(flowHash);
  161.  
  162. var namedFlows = namedFlowCollection.namedFlowMap;
  163. for (var flowName in namedFlows)
  164. this._appendNamedFlow(namedFlows[flowName]);
  165.  
  166. if (!this._flowTree.children.length)
  167. this._setSidebarHasContent(false);
  168. else
  169. this._showNamedFlowForNode(WebInspector.panel("elements").treeOutline.selectedDOMNode());
  170. },
  171.  
  172.  
  173. _namedFlowCreated: function(event)
  174. {
  175.  
  176. if (event.data.documentNodeId !== this._document.id)
  177. return;
  178.  
  179. var flow =   (event.data);
  180. this._appendNamedFlow(flow);
  181. },
  182.  
  183.  
  184. _namedFlowRemoved: function(event)
  185. {
  186.  
  187. if (event.data.documentNodeId !== this._document.id)
  188. return;
  189.  
  190. this._removeNamedFlow(this._hashNamedFlow(event.data.documentNodeId, event.data.flowName));
  191. },
  192.  
  193.  
  194. _regionLayoutUpdated: function(event)
  195. {
  196.  
  197. if (event.data.documentNodeId !== this._document.id)
  198. return;
  199.  
  200. var flow =   (event.data);
  201. this._updateNamedFlow(flow);
  202. },
  203.  
  204.  
  205. _hashNamedFlow: function(documentNodeId, flowName)
  206. {
  207. return documentNodeId + "|" + flowName;
  208. },
  209.  
  210.  
  211. _showNamedFlow: function(flowHash)
  212. {
  213. this._selectNamedFlowInSidebar(flowHash);
  214. this._selectNamedFlowTab(flowHash);
  215. },
  216.  
  217.  
  218. _selectNamedFlowInSidebar: function(flowHash)
  219. {
  220. this._namedFlows[flowHash].flowTreeItem.select(true);
  221. },
  222.  
  223.  
  224. _selectNamedFlowTab: function(flowHash)
  225. {
  226. var flowContainer = this._namedFlows[flowHash];
  227.  
  228. if (this._tabbedPane.selectedTabId === flowHash)
  229. return;
  230.  
  231. if (!this._tabbedPane.selectTab(flowHash)) {
  232. if (!flowContainer.flowView)
  233. flowContainer.flowView = new WebInspector.CSSNamedFlowView(flowContainer.flow);
  234.  
  235. this._tabbedPane.appendTab(flowHash, flowContainer.flow.name, flowContainer.flowView);
  236. this._tabbedPane.selectTab(flowHash);
  237. }
  238. },
  239.  
  240.  
  241. _selectedNodeChanged: function(event)
  242. {
  243. var node =   (event.data);
  244. this._showNamedFlowForNode(node);
  245. },
  246.  
  247.  
  248. _tabSelected: function(event)
  249. {
  250. this._selectNamedFlowInSidebar(event.data.tabId);
  251. },
  252.  
  253.  
  254. _tabClosed: function(event)
  255. {
  256. this._namedFlows[event.data.tabId].flowTreeItem.deselect();
  257. },
  258.  
  259.  
  260. _showNamedFlowForNode: function(node)
  261. {
  262. if (!node)
  263. return;
  264.  
  265. if (this._regionNodes[node.id]) {
  266. this._showNamedFlow(this._regionNodes[node.id]);
  267. return;
  268. }
  269.  
  270. while (node) {
  271. if (this._contentNodes[node.id]) {
  272. this._showNamedFlow(this._contentNodes[node.id]);
  273. return;
  274. }
  275.  
  276. node = node.parentNode;
  277. }
  278. },
  279.  
  280. wasShown: function()
  281. {
  282. WebInspector.SidebarView.prototype.wasShown.call(this);
  283.  
  284. WebInspector.domAgent.requestDocument(this._setDocument.bind(this));
  285.  
  286. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.DocumentUpdated, this._documentUpdated, this);
  287.  
  288. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.NamedFlowCreated, this._namedFlowCreated, this);
  289. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.NamedFlowRemoved, this._namedFlowRemoved, this);
  290. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.RegionLayoutUpdated, this._regionLayoutUpdated, this);
  291.  
  292. WebInspector.panel("elements").treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged, this._selectedNodeChanged, this);
  293.  
  294. this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
  295. this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabClosed, this._tabClosed, this);
  296. },
  297.  
  298. willHide: function()
  299. {
  300. WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.DocumentUpdated, this._documentUpdated, this);
  301.  
  302. WebInspector.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.NamedFlowCreated, this._namedFlowCreated, this);
  303. WebInspector.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.NamedFlowRemoved, this._namedFlowRemoved, this);
  304. WebInspector.cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.RegionLayoutUpdated, this._regionLayoutUpdated, this);
  305.  
  306. WebInspector.panel("elements").treeOutline.removeEventListener(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged, this._selectedNodeChanged, this);
  307.  
  308. this._tabbedPane.removeEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
  309. this._tabbedPane.removeEventListener(WebInspector.TabbedPane.EventTypes.TabClosed, this._tabClosed, this);
  310. },
  311.  
  312. __proto__: WebInspector.SidebarView.prototype
  313. }
  314.  
  315.  
  316. WebInspector.FlowTreeElement = function(flowContainer)
  317. {
  318. var container = document.createElement("div");
  319. container.createChild("div", "selection");
  320. container.createChild("span", "title").createChild("span").textContent = flowContainer.flow.name;
  321.  
  322. TreeElement.call(this, container, flowContainer, false);
  323.  
  324. this._overset = false;
  325. this.setOverset(flowContainer.flow.overset);
  326. }
  327.  
  328. WebInspector.FlowTreeElement.prototype = {
  329.  
  330. setOverset: function(newOverset)
  331. {
  332. if (this._overset === newOverset)
  333. return;
  334.  
  335. if (newOverset) {
  336. this.title.addStyleClass("named-flow-overflow");
  337. this.tooltip = WebInspector.UIString("Overflows.");
  338. } else {
  339. this.title.removeStyleClass("named-flow-overflow");
  340. this.tooltip = "";
  341. }
  342.  
  343. this._overset = newOverset;
  344. },
  345.  
  346. __proto__: TreeElement.prototype
  347. }
  348. ;
  349.  
  350.  
  351.  
  352. WebInspector.CSSNamedFlowView = function(flow)
  353. {
  354. WebInspector.View.call(this);
  355. this.element.addStyleClass("css-named-flow");
  356. this.element.addStyleClass("outline-disclosure");
  357.  
  358. this._treeOutline = new TreeOutline(this.element.createChild("ol"), true);
  359.  
  360. this._contentTreeItem = new TreeElement(WebInspector.UIString("content"), null, true);
  361. this._treeOutline.appendChild(this._contentTreeItem);
  362.  
  363. this._regionsTreeItem = new TreeElement(WebInspector.UIString("region chain"), null, true);
  364. this._regionsTreeItem.expand();
  365. this._treeOutline.appendChild(this._regionsTreeItem);
  366.  
  367. this._flow = flow;
  368.  
  369. var content = flow.content;
  370. for (var i = 0; i < content.length; ++i)
  371. this._insertContentNode(content[i]);
  372.  
  373. var regions = flow.regions;
  374. for (var i = 0; i < regions.length; ++i)
  375. this._insertRegion(regions[i]);
  376. }
  377.  
  378. WebInspector.CSSNamedFlowView.OversetTypeMessageMap = {
  379. empty: "empty",
  380. fit: "fit",
  381. overset: "overset"
  382. }
  383.  
  384. WebInspector.CSSNamedFlowView.prototype = {
  385.  
  386. _createFlowTreeOutline: function(rootDOMNode)
  387. {
  388. if (!rootDOMNode)
  389. return null;
  390.  
  391. var treeOutline = new WebInspector.ElementsTreeOutline(false, false, true);
  392. treeOutline.element.addStyleClass("named-flow-element");
  393. treeOutline.setVisible(true);
  394. treeOutline.rootDOMNode = rootDOMNode;
  395. treeOutline.wireToDomAgent();
  396. WebInspector.domAgent.removeEventListener(WebInspector.DOMAgent.Events.DocumentUpdated, treeOutline._elementsTreeUpdater._documentUpdated, treeOutline._elementsTreeUpdater);
  397.  
  398. return treeOutline;
  399. },
  400.  
  401.  
  402. _insertContentNode: function(contentNodeId, index)
  403. {
  404. var treeOutline = this._createFlowTreeOutline(WebInspector.domAgent.nodeForId(contentNodeId));
  405. var treeItem = new TreeElement(treeOutline.element, treeOutline);
  406.  
  407. if (index === undefined) {
  408. this._contentTreeItem.appendChild(treeItem);
  409. return;
  410. }
  411.  
  412. this._contentTreeItem.insertChild(treeItem, index);
  413. },
  414.  
  415.  
  416. _insertRegion: function(region, index)
  417. {
  418. var treeOutline = this._createFlowTreeOutline(WebInspector.domAgent.nodeForId(region.nodeId));
  419. treeOutline.element.addStyleClass("region-" + region.regionOverset);
  420.  
  421. var treeItem = new TreeElement(treeOutline.element, treeOutline);
  422. var oversetText = WebInspector.UIString(WebInspector.CSSNamedFlowView.OversetTypeMessageMap[region.regionOverset]);
  423. treeItem.tooltip = WebInspector.UIString("Region is %s.", oversetText);
  424.  
  425. if (index === undefined) {
  426. this._regionsTreeItem.appendChild(treeItem);
  427. return;
  428. }
  429.  
  430. this._regionsTreeItem.insertChild(treeItem, index);
  431. },
  432.  
  433. get flow()
  434. {
  435. return this._flow;
  436. },
  437.  
  438. set flow(newFlow)
  439. {
  440. this._update(newFlow);
  441. },
  442.  
  443.  
  444. _updateRegionOverset: function(regionTreeItem, newRegionOverset, oldRegionOverset)
  445. {
  446. var element = regionTreeItem.representedObject.element;
  447. element.removeStyleClass("region-" + oldRegionOverset);
  448. element.addStyleClass("region-" + newRegionOverset);
  449.  
  450. var oversetText = WebInspector.UIString(WebInspector.CSSNamedFlowView.OversetTypeMessageMap[newRegionOverset]);
  451. regionTreeItem.tooltip = WebInspector.UIString("Region is %s." , oversetText);
  452. },
  453.  
  454.  
  455. _mergeContentNodes: function(oldContent, newContent)
  456. {
  457. var nodeIdSet = {};
  458. for (var i = 0; i < newContent.length; ++i)
  459. nodeIdSet[newContent[i]] = true;
  460.  
  461. var oldContentIndex = 0;
  462. var newContentIndex = 0;
  463. var contentTreeChildIndex = 0;
  464.  
  465. while(oldContentIndex < oldContent.length || newContentIndex < newContent.length) {
  466. if (oldContentIndex === oldContent.length) {
  467. this._insertContentNode(newContent[newContentIndex]);
  468. ++newContentIndex;
  469. continue;
  470. }
  471.  
  472. if (newContentIndex === newContent.length) {
  473. this._contentTreeItem.removeChildAtIndex(contentTreeChildIndex);
  474. ++oldContentIndex;
  475. continue;
  476. }
  477.  
  478. if (oldContent[oldContentIndex] === newContent[newContentIndex]) {
  479. ++oldContentIndex;
  480. ++newContentIndex;
  481. ++contentTreeChildIndex;
  482. continue;
  483. }
  484.  
  485. if (nodeIdSet[oldContent[oldContentIndex]]) {
  486. this._insertContentNode(newContent[newContentIndex], contentTreeChildIndex);
  487. ++newContentIndex;
  488. ++contentTreeChildIndex;
  489. continue;
  490. }
  491.  
  492. this._contentTreeItem.removeChildAtIndex(contentTreeChildIndex);
  493. ++oldContentIndex;
  494. }
  495. },
  496.  
  497.  
  498. _mergeRegions: function(oldRegions, newRegions)
  499. {
  500. var nodeIdSet = {};
  501. for (var i = 0; i < newRegions.length; ++i)
  502. nodeIdSet[newRegions[i].nodeId] = true;
  503.  
  504. var oldRegionsIndex = 0;
  505. var newRegionsIndex = 0;
  506. var regionsTreeChildIndex = 0;
  507.  
  508. while(oldRegionsIndex < oldRegions.length || newRegionsIndex < newRegions.length) {
  509. if (oldRegionsIndex === oldRegions.length) {
  510. this._insertRegion(newRegions[newRegionsIndex]);
  511. ++newRegionsIndex;
  512. continue;
  513. }
  514.  
  515. if (newRegionsIndex === newRegions.length) {
  516. this._regionsTreeItem.removeChildAtIndex(regionsTreeChildIndex);
  517. ++oldRegionsIndex;
  518. continue;
  519. }
  520.  
  521. if (oldRegions[oldRegionsIndex].nodeId === newRegions[newRegionsIndex].nodeId) {
  522. if (oldRegions[oldRegionsIndex].regionOverset !== newRegions[newRegionsIndex].regionOverset)
  523. this._updateRegionOverset(this._regionsTreeItem.children[regionsTreeChildIndex], newRegions[newRegionsIndex].regionOverset, oldRegions[oldRegionsIndex].regionOverset);
  524. ++oldRegionsIndex;
  525. ++newRegionsIndex;
  526. ++regionsTreeChildIndex;
  527. continue;
  528. }
  529.  
  530. if (nodeIdSet[oldRegions[oldRegionsIndex].nodeId]) {
  531. this._insertRegion(newRegions[newRegionsIndex], regionsTreeChildIndex);
  532. ++newRegionsIndex;
  533. ++regionsTreeChildIndex;
  534. continue;
  535. }
  536.  
  537. this._regionsTreeItem.removeChildAtIndex(regionsTreeChildIndex);
  538. ++oldRegionsIndex;
  539. }
  540. },
  541.  
  542.  
  543. _update: function(newFlow)
  544. {
  545. this._mergeContentNodes(this._flow.content, newFlow.content);
  546. this._mergeRegions(this._flow.regions, newFlow.regions);
  547.  
  548. this._flow = newFlow;
  549. },
  550.  
  551. __proto__: WebInspector.View.prototype
  552. }
  553. ;
  554.  
  555.  
  556.  
  557. WebInspector.EventListenersSidebarPane = function()
  558. {
  559. WebInspector.SidebarPane.call(this, WebInspector.UIString("Event Listeners"));
  560. this.bodyElement.addStyleClass("events-pane");
  561.  
  562. this.sections = [];
  563.  
  564. this.settingsSelectElement = document.createElement("select");
  565. this.settingsSelectElement.className = "select-filter";
  566.  
  567. var option = document.createElement("option");
  568. option.value = "all";
  569. option.label = WebInspector.UIString("All Nodes");
  570. this.settingsSelectElement.appendChild(option);
  571.  
  572. option = document.createElement("option");
  573. option.value = "selected";
  574. option.label = WebInspector.UIString("Selected Node Only");
  575. this.settingsSelectElement.appendChild(option);
  576.  
  577. var filter = WebInspector.settings.eventListenersFilter.get();
  578. if (filter === "all")
  579. this.settingsSelectElement[0].selected = true;
  580. else if (filter === "selected")
  581. this.settingsSelectElement[1].selected = true;
  582. this.settingsSelectElement.addEventListener("click", function(event) { event.consume() }, false);
  583. this.settingsSelectElement.addEventListener("change", this._changeSetting.bind(this), false);
  584.  
  585. this.titleElement.appendChild(this.settingsSelectElement);
  586.  
  587. this._linkifier = new WebInspector.Linkifier();
  588. }
  589.  
  590. WebInspector.EventListenersSidebarPane._objectGroupName = "event-listeners-sidebar-pane";
  591.  
  592. WebInspector.EventListenersSidebarPane.prototype = {
  593. update: function(node)
  594. {
  595. RuntimeAgent.releaseObjectGroup(WebInspector.EventListenersSidebarPane._objectGroupName);
  596. this._linkifier.reset();
  597.  
  598. var body = this.bodyElement;
  599. body.removeChildren();
  600. this.sections = [];
  601.  
  602. var self = this;
  603. function callback(error, eventListeners) {
  604. if (error)
  605. return;
  606.  
  607. var selectedNodeOnly = "selected" === WebInspector.settings.eventListenersFilter.get();
  608. var sectionNames = [];
  609. var sectionMap = {};
  610. for (var i = 0; i < eventListeners.length; ++i) {
  611. var eventListener = eventListeners[i];
  612. if (selectedNodeOnly && (node.id !== eventListener.nodeId))
  613. continue;
  614. eventListener.node = WebInspector.domAgent.nodeForId(eventListener.nodeId);
  615. delete eventListener.nodeId; 
  616. if (/^function _inspectorCommandLineAPI_logEvent\(/.test(eventListener.handlerBody.toString()))
  617. continue; 
  618. var type = eventListener.type;
  619. var section = sectionMap[type];
  620. if (!section) {
  621. section = new WebInspector.EventListenersSection(type, node.id, self._linkifier);
  622. sectionMap[type] = section;
  623. sectionNames.push(type);
  624. self.sections.push(section);
  625. }
  626. section.addListener(eventListener);
  627. }
  628.  
  629. if (sectionNames.length === 0) {
  630. var div = document.createElement("div");
  631. div.className = "info";
  632. div.textContent = WebInspector.UIString("No Event Listeners");
  633. body.appendChild(div);
  634. return;
  635. }
  636.  
  637. sectionNames.sort();
  638. for (var i = 0; i < sectionNames.length; ++i) {
  639. var section = sectionMap[sectionNames[i]];
  640. body.appendChild(section.element);
  641. }
  642. }
  643.  
  644. if (node)
  645. node.eventListeners(callback);
  646. this._selectedNode = node;
  647. },
  648.  
  649. willHide: function()
  650. {
  651. delete this._selectedNode;
  652. },
  653.  
  654. _changeSetting: function()
  655. {
  656. var selectedOption = this.settingsSelectElement[this.settingsSelectElement.selectedIndex];
  657. WebInspector.settings.eventListenersFilter.set(selectedOption.value);
  658. this.update(this._selectedNode);
  659. },
  660.  
  661. __proto__: WebInspector.SidebarPane.prototype
  662. }
  663.  
  664.  
  665. WebInspector.EventListenersSection = function(title, nodeId, linkifier)
  666. {
  667. this.eventListeners = [];
  668. this._nodeId = nodeId;
  669. this._linkifier = linkifier;
  670. WebInspector.PropertiesSection.call(this, title);
  671.  
  672.  
  673. this.propertiesElement.parentNode.removeChild(this.propertiesElement);
  674. delete this.propertiesElement;
  675. delete this.propertiesTreeOutline;
  676.  
  677. this._eventBars = document.createElement("div");
  678. this._eventBars.className = "event-bars";
  679. this.element.appendChild(this._eventBars);
  680. }
  681.  
  682. WebInspector.EventListenersSection.prototype = {
  683. addListener: function(eventListener)
  684. {
  685. var eventListenerBar = new WebInspector.EventListenerBar(eventListener, this._nodeId, this._linkifier);
  686. this._eventBars.appendChild(eventListenerBar.element);
  687. },
  688.  
  689. __proto__: WebInspector.PropertiesSection.prototype
  690. }
  691.  
  692.  
  693. WebInspector.EventListenerBar = function(eventListener, nodeId, linkifier)
  694. {
  695. WebInspector.ObjectPropertiesSection.call(this, WebInspector.RemoteObject.fromPrimitiveValue(""));
  696.  
  697. this.eventListener = eventListener;
  698. this._nodeId = nodeId;
  699. this._setNodeTitle();
  700. this._setFunctionSubtitle(linkifier);
  701. this.editable = false;
  702. this.element.className = "event-bar";  
  703. this.headerElement.addStyleClass("source-code");
  704. this.propertiesElement.className = "event-properties properties-tree source-code";  
  705. }
  706.  
  707. WebInspector.EventListenerBar.prototype = {
  708. update: function()
  709. {
  710. function updateWithNodeObject(nodeObject)
  711. {
  712. var properties = [];
  713.  
  714. if (this.eventListener.type)
  715. properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("type", this.eventListener.type));
  716. if (typeof this.eventListener.useCapture !== "undefined")
  717. properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("useCapture", this.eventListener.useCapture));
  718. if (typeof this.eventListener.isAttribute !== "undefined")
  719. properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("isAttribute", this.eventListener.isAttribute));
  720. if (nodeObject)
  721. properties.push(new WebInspector.RemoteObjectProperty("node", nodeObject));
  722. if (typeof this.eventListener.handlerBody !== "undefined")
  723. properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("listenerBody", this.eventListener.handlerBody));
  724. if (this.eventListener.sourceName)
  725. properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("sourceName", this.eventListener.sourceName));
  726. if (this.eventListener.location)
  727. properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("lineNumber", this.eventListener.location.lineNumber + 1));
  728.  
  729. this.updateProperties(properties);
  730. }
  731. WebInspector.RemoteObject.resolveNode(this.eventListener.node, WebInspector.EventListenersSidebarPane._objectGroupName, updateWithNodeObject.bind(this));
  732. },
  733.  
  734. _setNodeTitle: function()
  735. {
  736. var node = this.eventListener.node;
  737. if (!node)
  738. return;
  739.  
  740. if (node.nodeType() === Node.DOCUMENT_NODE) {
  741. this.titleElement.textContent = "document";
  742. return;
  743. }
  744.  
  745. if (node.id === this._nodeId) {
  746. this.titleElement.textContent = node.appropriateSelectorFor();
  747. return;
  748. }
  749.  
  750. this.titleElement.removeChildren();
  751. this.titleElement.appendChild(WebInspector.DOMPresentationUtils.linkifyNodeReference(this.eventListener.node));
  752. },
  753.  
  754. _setFunctionSubtitle: function(linkifier)
  755. {
  756.  
  757. if (this.eventListener.location) {
  758. this.subtitleElement.removeChildren();
  759. var urlElement;
  760. if (this.eventListener.location.scriptId)
  761. urlElement = linkifier.linkifyRawLocation(this.eventListener.location);
  762. if (!urlElement) {
  763. var url = this.eventListener.sourceName;
  764. var lineNumber = this.eventListener.location.lineNumber;
  765. var columnNumber = 0;
  766. urlElement = linkifier.linkifyLocation(url, lineNumber, columnNumber);
  767. }
  768. this.subtitleElement.appendChild(urlElement);
  769. } else {
  770. var match = this.eventListener.handlerBody.match(/function ([^\(]+?)\(/);
  771. if (match)
  772. this.subtitleElement.textContent = match[1];
  773. else
  774. this.subtitleElement.textContent = WebInspector.UIString("(anonymous function)");
  775. }
  776. },
  777.  
  778. __proto__: WebInspector.ObjectPropertiesSection.prototype
  779. }
  780. ;
  781.  
  782.  
  783.  
  784. WebInspector.MetricsSidebarPane = function()
  785. {
  786. WebInspector.SidebarPane.call(this, WebInspector.UIString("Metrics"));
  787.  
  788. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetChanged, this._styleSheetOrMediaQueryResultChanged, this);
  789. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.MediaQueryResultChanged, this._styleSheetOrMediaQueryResultChanged, this);
  790. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, this._attributesUpdated, this);
  791. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrRemoved, this._attributesUpdated, this);
  792. }
  793.  
  794. WebInspector.MetricsSidebarPane.prototype = {
  795.  
  796. update: function(node)
  797. {
  798. if (node)
  799. this.node = node;
  800. this._innerUpdate();
  801. },
  802.  
  803. _innerUpdate: function()
  804. {
  805.  
  806.  
  807. if (this._isEditingMetrics)
  808. return;
  809.  
  810.  
  811. var node = this.node;
  812.  
  813. if (!node || node.nodeType() !== Node.ELEMENT_NODE) {
  814. this.bodyElement.removeChildren();
  815. return;
  816. }
  817.  
  818. function callback(style)
  819. {
  820. if (!style || this.node !== node)
  821. return;
  822. this._updateMetrics(style);
  823. }
  824. WebInspector.cssModel.getComputedStyleAsync(node.id, callback.bind(this));
  825.  
  826. function inlineStyleCallback(style)
  827. {
  828. if (!style || this.node !== node)
  829. return;
  830. this.inlineStyle = style;
  831. }
  832. WebInspector.cssModel.getInlineStylesAsync(node.id, inlineStyleCallback.bind(this));
  833. },
  834.  
  835. _styleSheetOrMediaQueryResultChanged: function()
  836. {
  837. this._innerUpdate();
  838. },
  839.  
  840. _attributesUpdated: function(event)
  841. {
  842. if (this.node !== event.data.node)
  843. return;
  844.  
  845. this._innerUpdate();
  846. },
  847.  
  848. _getPropertyValueAsPx: function(style, propertyName)
  849. {
  850. return Number(style.getPropertyValue(propertyName).replace(/px$/, "") || 0);
  851. },
  852.  
  853. _getBox: function(computedStyle, componentName)
  854. {
  855. var suffix = componentName === "border" ? "-width" : "";
  856. var left = this._getPropertyValueAsPx(computedStyle, componentName + "-left" + suffix);
  857. var top = this._getPropertyValueAsPx(computedStyle, componentName + "-top" + suffix);
  858. var right = this._getPropertyValueAsPx(computedStyle, componentName + "-right" + suffix);
  859. var bottom = this._getPropertyValueAsPx(computedStyle, componentName + "-bottom" + suffix);
  860. return { left: left, top: top, right: right, bottom: bottom };
  861. },
  862.  
  863. _highlightDOMNode: function(showHighlight, mode, event)
  864. {
  865. event.consume();
  866. var nodeId = showHighlight && this.node ? this.node.id : 0;
  867. if (nodeId) {
  868. if (this._highlightMode === mode)
  869. return;
  870. this._highlightMode = mode;
  871. WebInspector.domAgent.highlightDOMNode(nodeId, mode);
  872. } else {
  873. delete this._highlightMode;
  874. WebInspector.domAgent.hideDOMNodeHighlight();
  875. }
  876.  
  877. for (var i = 0; this._boxElements && i < this._boxElements.length; ++i) {
  878. var element = this._boxElements[i];
  879. if (!nodeId || mode === "all" || element._name === mode)
  880. element.style.backgroundColor = element._backgroundColor;
  881. else
  882. element.style.backgroundColor = "";
  883. }
  884. },
  885.  
  886. _updateMetrics: function(style)
  887. {
  888.  
  889. var metricsElement = document.createElement("div");
  890. metricsElement.className = "metrics";
  891. var self = this;
  892.  
  893. function createBoxPartElement(style, name, side, suffix)
  894. {
  895. var propertyName = (name !== "position" ? name + "-" : "") + side + suffix;
  896. var value = style.getPropertyValue(propertyName);
  897. if (value === "" || (name !== "position" && value === "0px"))
  898. value = "\u2012";
  899. else if (name === "position" && value === "auto")
  900. value = "\u2012";
  901. value = value.replace(/px$/, "");
  902.  
  903. var element = document.createElement("div");
  904. element.className = side;
  905. element.textContent = value;
  906. element.addEventListener("dblclick", this.startEditing.bind(this, element, name, propertyName, style), false);
  907. return element;
  908. }
  909.  
  910. function getContentAreaWidthPx(style)
  911. {
  912. var width = style.getPropertyValue("width").replace(/px$/, "");
  913. if (style.getPropertyValue("box-sizing") === "border-box") {
  914. var borderBox = self._getBox(style, "border");
  915. var paddingBox = self._getBox(style, "padding");
  916.  
  917. width = width - borderBox.left - borderBox.right - paddingBox.left - paddingBox.right;
  918. }
  919.  
  920. return width;
  921. }
  922.  
  923. function getContentAreaHeightPx(style)
  924. {
  925. var height = style.getPropertyValue("height").replace(/px$/, "");
  926. if (style.getPropertyValue("box-sizing") === "border-box") {
  927. var borderBox = self._getBox(style, "border");
  928. var paddingBox = self._getBox(style, "padding");
  929.  
  930. height = height - borderBox.top - borderBox.bottom - paddingBox.top - paddingBox.bottom;
  931. }
  932.  
  933. return height;
  934. }
  935.  
  936.  
  937. var noMarginDisplayType = {
  938. "table-cell": true,
  939. "table-column": true,
  940. "table-column-group": true,
  941. "table-footer-group": true,
  942. "table-header-group": true,
  943. "table-row": true,
  944. "table-row-group": true
  945. };
  946.  
  947.  
  948. var noPaddingDisplayType = {
  949. "table-column": true,
  950. "table-column-group": true,
  951. "table-footer-group": true,
  952. "table-header-group": true,
  953. "table-row": true,
  954. "table-row-group": true
  955. };
  956.  
  957.  
  958. var noPositionType = {
  959. "static": true
  960. };
  961.  
  962. var boxes = ["content", "padding", "border", "margin", "position"];
  963. var boxColors = [
  964. WebInspector.Color.PageHighlight.Content,
  965. WebInspector.Color.PageHighlight.Padding,
  966. WebInspector.Color.PageHighlight.Border,
  967. WebInspector.Color.PageHighlight.Margin,
  968. WebInspector.Color.fromRGBA(0, 0, 0, 0)
  969. ];
  970. var boxLabels = [WebInspector.UIString("content"), WebInspector.UIString("padding"), WebInspector.UIString("border"), WebInspector.UIString("margin"), WebInspector.UIString("position")];
  971. var previousBox = null;
  972. this._boxElements = [];
  973. for (var i = 0; i < boxes.length; ++i) {
  974. var name = boxes[i];
  975.  
  976. if (name === "margin" && noMarginDisplayType[style.getPropertyValue("display")])
  977. continue;
  978. if (name === "padding" && noPaddingDisplayType[style.getPropertyValue("display")])
  979. continue;
  980. if (name === "position" && noPositionType[style.getPropertyValue("position")])
  981. continue;
  982.  
  983. var boxElement = document.createElement("div");
  984. boxElement.className = name;
  985. boxElement._backgroundColor = boxColors[i].toString("original");
  986. boxElement._name = name;
  987. boxElement.style.backgroundColor = boxElement._backgroundColor;
  988. boxElement.addEventListener("mouseover", this._highlightDOMNode.bind(this, true, name === "position" ? "all" : name), false);
  989. this._boxElements.push(boxElement);
  990.  
  991. if (name === "content") {
  992. var widthElement = document.createElement("span");
  993. widthElement.textContent = getContentAreaWidthPx(style);
  994. widthElement.addEventListener("dblclick", this.startEditing.bind(this, widthElement, "width", "width", style), false);
  995.  
  996. var heightElement = document.createElement("span");
  997. heightElement.textContent = getContentAreaHeightPx(style);
  998. heightElement.addEventListener("dblclick", this.startEditing.bind(this, heightElement, "height", "height", style), false);
  999.  
  1000. boxElement.appendChild(widthElement);
  1001. boxElement.appendChild(document.createTextNode(" \u00D7 "));
  1002. boxElement.appendChild(heightElement);
  1003. } else {
  1004. var suffix = (name === "border" ? "-width" : "");
  1005.  
  1006. var labelElement = document.createElement("div");
  1007. labelElement.className = "label";
  1008. labelElement.textContent = boxLabels[i];
  1009. boxElement.appendChild(labelElement);
  1010.  
  1011. boxElement.appendChild(createBoxPartElement.call(this, style, name, "top", suffix));
  1012. boxElement.appendChild(document.createElement("br"));
  1013. boxElement.appendChild(createBoxPartElement.call(this, style, name, "left", suffix));
  1014.  
  1015. if (previousBox)
  1016. boxElement.appendChild(previousBox);
  1017.  
  1018. boxElement.appendChild(createBoxPartElement.call(this, style, name, "right", suffix));
  1019. boxElement.appendChild(document.createElement("br"));
  1020. boxElement.appendChild(createBoxPartElement.call(this, style, name, "bottom", suffix));
  1021. }
  1022.  
  1023. previousBox = boxElement;
  1024. }
  1025.  
  1026. metricsElement.appendChild(previousBox);
  1027. metricsElement.addEventListener("mouseover", this._highlightDOMNode.bind(this, false, ""), false);
  1028. this.bodyElement.removeChildren();
  1029. this.bodyElement.appendChild(metricsElement);
  1030. },
  1031.  
  1032. startEditing: function(targetElement, box, styleProperty, computedStyle)
  1033. {
  1034. if (WebInspector.isBeingEdited(targetElement))
  1035. return;
  1036.  
  1037. var context = { box: box, styleProperty: styleProperty, computedStyle: computedStyle };
  1038. var boundKeyDown = this._handleKeyDown.bind(this, context, styleProperty);
  1039. context.keyDownHandler = boundKeyDown;
  1040. targetElement.addEventListener("keydown", boundKeyDown, false);
  1041.  
  1042. this._isEditingMetrics = true;
  1043.  
  1044. var config = new WebInspector.EditingConfig(this.editingCommitted.bind(this), this.editingCancelled.bind(this), context);
  1045. WebInspector.startEditing(targetElement, config);
  1046.  
  1047. window.getSelection().setBaseAndExtent(targetElement, 0, targetElement, 1);
  1048. },
  1049.  
  1050. _handleKeyDown: function(context, styleProperty, event)
  1051. {
  1052. var element = event.currentTarget;
  1053.  
  1054. function finishHandler(originalValue, replacementString)
  1055. {
  1056. this._applyUserInput(element, replacementString, originalValue, context, false);
  1057. }
  1058.  
  1059. function customNumberHandler(number)
  1060. {
  1061. if (styleProperty !== "margin" && number < 0)
  1062. number = 0;
  1063. return number;
  1064. }
  1065.  
  1066. WebInspector.handleElementValueModifications(event, element, finishHandler.bind(this), undefined, customNumberHandler);
  1067. },
  1068.  
  1069. editingEnded: function(element, context)
  1070. {
  1071. delete this.originalPropertyData;
  1072. delete this.previousPropertyDataCandidate;
  1073. element.removeEventListener("keydown", context.keyDownHandler, false);
  1074. delete this._isEditingMetrics;
  1075. },
  1076.  
  1077. editingCancelled: function(element, context)
  1078. {
  1079. if ("originalPropertyData" in this && this.inlineStyle) {
  1080. if (!this.originalPropertyData) {
  1081.  
  1082. var pastLastSourcePropertyIndex = this.inlineStyle.pastLastSourcePropertyIndex();
  1083. if (pastLastSourcePropertyIndex)
  1084. this.inlineStyle.allProperties[pastLastSourcePropertyIndex - 1].setText("", false);
  1085. } else
  1086. this.inlineStyle.allProperties[this.originalPropertyData.index].setText(this.originalPropertyData.propertyText, false);
  1087. }
  1088. this.editingEnded(element, context);
  1089. this.update();
  1090. },
  1091.  
  1092. _applyUserInput: function(element, userInput, previousContent, context, commitEditor)
  1093. {
  1094. if (!this.inlineStyle) {
  1095.  
  1096. return this.editingCancelled(element, context); 
  1097. }
  1098.  
  1099. if (commitEditor && userInput === previousContent)
  1100. return this.editingCancelled(element, context); 
  1101.  
  1102. if (context.box !== "position" && (!userInput || userInput === "\u2012"))
  1103. userInput = "0px";
  1104. else if (context.box === "position" && (!userInput || userInput === "\u2012"))
  1105. userInput = "auto";
  1106.  
  1107. userInput = userInput.toLowerCase();
  1108.  
  1109. if (/^\d+$/.test(userInput))
  1110. userInput += "px";
  1111.  
  1112. var styleProperty = context.styleProperty;
  1113. var computedStyle = context.computedStyle;
  1114.  
  1115. if (computedStyle.getPropertyValue("box-sizing") === "border-box" && (styleProperty === "width" || styleProperty === "height")) {
  1116. if (!userInput.match(/px$/)) {
  1117. WebInspector.log("For elements with box-sizing: border-box, only absolute content area dimensions can be applied", WebInspector.ConsoleMessage.MessageLevel.Error, true);
  1118. return;
  1119. }
  1120.  
  1121. var borderBox = this._getBox(computedStyle, "border");
  1122. var paddingBox = this._getBox(computedStyle, "padding");
  1123. var userValuePx = Number(userInput.replace(/px$/, ""));
  1124. if (isNaN(userValuePx))
  1125. return;
  1126. if (styleProperty === "width")
  1127. userValuePx += borderBox.left + borderBox.right + paddingBox.left + paddingBox.right;
  1128. else
  1129. userValuePx += borderBox.top + borderBox.bottom + paddingBox.top + paddingBox.bottom;
  1130.  
  1131. userInput = userValuePx + "px";
  1132. }
  1133.  
  1134. this.previousPropertyDataCandidate = null;
  1135. var self = this;
  1136. var callback = function(style) {
  1137. if (!style)
  1138. return;
  1139. self.inlineStyle = style;
  1140. if (!("originalPropertyData" in self))
  1141. self.originalPropertyData = self.previousPropertyDataCandidate;
  1142.  
  1143. if (typeof self._highlightMode !== "undefined") {
  1144. WebInspector.domAgent.highlightDOMNode(self.node.id, self._highlightMode);
  1145. }
  1146.  
  1147. if (commitEditor) {
  1148. self.dispatchEventToListeners("metrics edited");
  1149. self.update();
  1150. }
  1151. };
  1152.  
  1153. var allProperties = this.inlineStyle.allProperties;
  1154. for (var i = 0; i < allProperties.length; ++i) {
  1155. var property = allProperties[i];
  1156. if (property.name !== context.styleProperty || property.inactive)
  1157. continue;
  1158.  
  1159. this.previousPropertyDataCandidate = property;
  1160. property.setValue(userInput, commitEditor, true, callback);
  1161. return;
  1162. }
  1163.  
  1164. this.inlineStyle.appendProperty(context.styleProperty, userInput, callback);
  1165. },
  1166.  
  1167. editingCommitted: function(element, userInput, previousContent, context)
  1168. {
  1169. this.editingEnded(element, context);
  1170. this._applyUserInput(element, userInput, previousContent, context, true);
  1171. },
  1172.  
  1173. __proto__: WebInspector.SidebarPane.prototype
  1174. }
  1175. ;
  1176.  
  1177.  
  1178.  
  1179. WebInspector.PropertiesSidebarPane = function()
  1180. {
  1181. WebInspector.SidebarPane.call(this, WebInspector.UIString("Properties"));
  1182. }
  1183.  
  1184. WebInspector.PropertiesSidebarPane._objectGroupName = "properties-sidebar-pane";
  1185.  
  1186. WebInspector.PropertiesSidebarPane.prototype = {
  1187. update: function(node)
  1188. {
  1189. var body = this.bodyElement;
  1190.  
  1191. if (!node) {
  1192. body.removeChildren();
  1193. this.sections = [];
  1194. return;
  1195. }
  1196.  
  1197. WebInspector.RemoteObject.resolveNode(node, WebInspector.PropertiesSidebarPane._objectGroupName, nodeResolved.bind(this));
  1198.  
  1199. function nodeResolved(object)
  1200. {
  1201. if (!object)
  1202. return;
  1203. function protoList()
  1204. {
  1205. var proto = this;
  1206. var result = {};
  1207. var counter = 1;
  1208. while (proto) {
  1209. result[counter++] = proto;
  1210. proto = proto.__proto__;
  1211. }
  1212. return result;
  1213. }
  1214. object.callFunction(protoList, undefined, nodePrototypesReady.bind(this));
  1215. object.release();
  1216. }
  1217.  
  1218. function nodePrototypesReady(object)
  1219. {
  1220. if (!object)
  1221. return;
  1222. object.getOwnProperties(fillSection.bind(this));
  1223. }
  1224.  
  1225. function fillSection(prototypes)
  1226. {
  1227. if (!prototypes)
  1228. return;
  1229.  
  1230. var body = this.bodyElement;
  1231. body.removeChildren();
  1232. this.sections = [];
  1233.  
  1234.  
  1235. for (var i = 0; i < prototypes.length; ++i) {
  1236. if (!parseInt(prototypes[i].name, 10))
  1237. continue;
  1238.  
  1239. var prototype = prototypes[i].value;
  1240. var title = prototype.description;
  1241. if (title.match(/Prototype$/))
  1242. title = title.replace(/Prototype$/, "");
  1243. var section = new WebInspector.ObjectPropertiesSection(prototype, title);
  1244. this.sections.push(section);
  1245. body.appendChild(section.element);
  1246. }
  1247. }
  1248. },
  1249.  
  1250. __proto__: WebInspector.SidebarPane.prototype
  1251. }
  1252. ;
  1253.  
  1254.  
  1255.  
  1256. WebInspector.StylesSidebarPane = function(computedStylePane, setPseudoClassCallback)
  1257. {
  1258. WebInspector.SidebarPane.call(this, WebInspector.UIString("Styles"));
  1259.  
  1260. this.settingsSelectElement = document.createElement("select");
  1261. this.settingsSelectElement.className = "select-settings";
  1262.  
  1263. var option = document.createElement("option");
  1264. option.value = WebInspector.Color.Format.Original;
  1265. option.label = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "As authored" : "As Authored");
  1266. this.settingsSelectElement.appendChild(option);
  1267.  
  1268. option = document.createElement("option");
  1269. option.value = WebInspector.Color.Format.HEX;
  1270. option.label = WebInspector.UIString("Hex Colors");
  1271. this.settingsSelectElement.appendChild(option);
  1272.  
  1273. option = document.createElement("option");
  1274. option.value = WebInspector.Color.Format.RGB;
  1275. option.label = WebInspector.UIString("RGB Colors");
  1276. this.settingsSelectElement.appendChild(option);
  1277.  
  1278. option = document.createElement("option");
  1279. option.value = WebInspector.Color.Format.HSL;
  1280. option.label = WebInspector.UIString("HSL Colors");
  1281. this.settingsSelectElement.appendChild(option);
  1282.  
  1283.  
  1284. var muteEventListener = function(event) { event.consume(true); };
  1285.  
  1286. this.settingsSelectElement.addEventListener("click", muteEventListener, true);
  1287. this.settingsSelectElement.addEventListener("change", this._changeSetting.bind(this), false);
  1288. this._updateColorFormatFilter();
  1289.  
  1290. this.titleElement.appendChild(this.settingsSelectElement);
  1291.  
  1292. this._elementStateButton = document.createElement("button");
  1293. this._elementStateButton.className = "pane-title-button element-state";
  1294. this._elementStateButton.title = WebInspector.UIString("Toggle Element State");
  1295. this._elementStateButton.addEventListener("click", this._toggleElementStatePane.bind(this), false);
  1296. this.titleElement.appendChild(this._elementStateButton);
  1297.  
  1298. var addButton = document.createElement("button");
  1299. addButton.className = "pane-title-button add";
  1300. addButton.id = "add-style-button-test-id";
  1301. addButton.title = WebInspector.UIString("New Style Rule");
  1302. addButton.addEventListener("click", this._createNewRule.bind(this), false);
  1303. this.titleElement.appendChild(addButton);
  1304.  
  1305. this._computedStylePane = computedStylePane;
  1306. computedStylePane._stylesSidebarPane = this;
  1307. this._setPseudoClassCallback = setPseudoClassCallback;
  1308. this.element.addEventListener("contextmenu", this._contextMenuEventFired.bind(this), true);
  1309. WebInspector.settings.colorFormat.addChangeListener(this._colorFormatSettingChanged.bind(this));
  1310.  
  1311. this._createElementStatePane();
  1312. this.bodyElement.appendChild(this._elementStatePane);
  1313. this._sectionsContainer = document.createElement("div");
  1314. this.bodyElement.appendChild(this._sectionsContainer);
  1315.  
  1316. this._spectrumHelper = new WebInspector.SpectrumPopupHelper();
  1317. this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.DefaultCSSFormatter());
  1318.  
  1319. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetChanged, this._styleSheetOrMediaQueryResultChanged, this);
  1320. WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.MediaQueryResultChanged, this._styleSheetOrMediaQueryResultChanged, this);
  1321. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, this._attributeChanged, this);
  1322. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrRemoved, this._attributeChanged, this);
  1323. WebInspector.settings.showUserAgentStyles.addChangeListener(this._showUserAgentStylesSettingChanged.bind(this));
  1324. }
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330. WebInspector.StylesSidebarPane.PseudoIdNames = [
  1331. "", "first-line", "first-letter", "before", "after", "selection", "", "-webkit-scrollbar", "-webkit-file-upload-button",
  1332. "-webkit-input-placeholder", "-webkit-slider-thumb", "-webkit-search-cancel-button", "-webkit-search-decoration",
  1333. "-webkit-search-results-decoration", "-webkit-search-results-button", "-webkit-media-controls-panel",
  1334. "-webkit-media-controls-play-button", "-webkit-media-controls-mute-button", "-webkit-media-controls-timeline",
  1335. "-webkit-media-controls-timeline-container", "-webkit-media-controls-volume-slider",
  1336. "-webkit-media-controls-volume-slider-container", "-webkit-media-controls-current-time-display",
  1337. "-webkit-media-controls-time-remaining-display", "-webkit-media-controls-seek-back-button", "-webkit-media-controls-seek-forward-button",
  1338. "-webkit-media-controls-fullscreen-button", "-webkit-media-controls-rewind-button", "-webkit-media-controls-return-to-realtime-button",
  1339. "-webkit-media-controls-toggle-closed-captions-button", "-webkit-media-controls-status-display", "-webkit-scrollbar-thumb",
  1340. "-webkit-scrollbar-button", "-webkit-scrollbar-track", "-webkit-scrollbar-track-piece", "-webkit-scrollbar-corner",
  1341. "-webkit-resizer", "-webkit-inner-spin-button", "-webkit-outer-spin-button"
  1342. ];
  1343.  
  1344. WebInspector.StylesSidebarPane.canonicalPropertyName = function(name)
  1345. {
  1346. if (!name || name.length < 9 || name.charAt(0) !== "-")
  1347. return name;
  1348. var match = name.match(/(?:-webkit-|-khtml-|-apple-)(.+)/);
  1349. if (!match)
  1350. return name;
  1351. return match[1];
  1352. }
  1353.  
  1354. WebInspector.StylesSidebarPane.createExclamationMark = function(propertyName)
  1355. {
  1356. var exclamationElement = document.createElement("img");
  1357. exclamationElement.className = "exclamation-mark";
  1358. exclamationElement.title = WebInspector.CSSCompletions.cssPropertiesMetainfo.keySet()[propertyName.toLowerCase()] ? WebInspector.UIString("Invalid property value.") : WebInspector.UIString("Unknown property name.");
  1359. return exclamationElement;
  1360. }
  1361.  
  1362. WebInspector.StylesSidebarPane.prototype = {
  1363. _contextMenuEventFired: function(event)
  1364. {
  1365.  
  1366.  
  1367. var contextMenu = new WebInspector.ContextMenu(event);
  1368. contextMenu.appendApplicableItems(event.target);
  1369. contextMenu.show();
  1370. },
  1371.  
  1372. get _forcedPseudoClasses()
  1373. {
  1374. return this.node ? (this.node.getUserProperty("pseudoState") || undefined) : undefined;
  1375. },
  1376.  
  1377. _updateForcedPseudoStateInputs: function()
  1378. {
  1379. if (!this.node)
  1380. return;
  1381.  
  1382. var nodePseudoState = this._forcedPseudoClasses;
  1383. if (!nodePseudoState)
  1384. nodePseudoState = [];
  1385.  
  1386. var inputs = this._elementStatePane.inputs;
  1387. for (var i = 0; i < inputs.length; ++i)
  1388. inputs[i].checked = nodePseudoState.indexOf(inputs[i].state) >= 0;
  1389. },
  1390.  
  1391. update: function(node, forceUpdate)
  1392. {
  1393. this._spectrumHelper.hide();
  1394.  
  1395. var refresh = false;
  1396.  
  1397. if (forceUpdate)
  1398. delete this.node;
  1399.  
  1400. if (!forceUpdate && (node === this.node))
  1401. refresh = true;
  1402.  
  1403. if (node && node.nodeType() === Node.TEXT_NODE && node.parentNode)
  1404. node = node.parentNode;
  1405.  
  1406. if (node && node.nodeType() !== Node.ELEMENT_NODE)
  1407. node = null;
  1408.  
  1409. if (node)
  1410. this.node = node;
  1411. else
  1412. node = this.node;
  1413.  
  1414. this._updateForcedPseudoStateInputs();
  1415.  
  1416. if (refresh)
  1417. this._refreshUpdate();
  1418. else
  1419. this._rebuildUpdate();
  1420. },
  1421.  
  1422.  
  1423. _refreshUpdate: function(editedSection, forceFetchComputedStyle, userCallback)
  1424. {
  1425. if (this._refreshUpdateInProgress) {
  1426. this._lastNodeForInnerRefresh = this.node;
  1427. return;
  1428. }
  1429.  
  1430. var node = this._validateNode(userCallback);
  1431. if (!node)
  1432. return;
  1433.  
  1434. function computedStyleCallback(computedStyle)
  1435. {
  1436. delete this._refreshUpdateInProgress;
  1437.  
  1438. if (this._lastNodeForInnerRefresh) {
  1439. delete this._lastNodeForInnerRefresh;
  1440. this._refreshUpdate(editedSection, forceFetchComputedStyle, userCallback);
  1441. return;
  1442. }
  1443.  
  1444. if (this.node === node && computedStyle)
  1445. this._innerRefreshUpdate(node, computedStyle, editedSection);
  1446.  
  1447. if (userCallback)
  1448. userCallback();
  1449. }
  1450.  
  1451. if (this._computedStylePane.expanded || forceFetchComputedStyle) {
  1452. this._refreshUpdateInProgress = true;
  1453. WebInspector.cssModel.getComputedStyleAsync(node.id, computedStyleCallback.bind(this));
  1454. } else {
  1455. this._innerRefreshUpdate(node, null, editedSection);
  1456. if (userCallback)
  1457. userCallback();
  1458. }
  1459. },
  1460.  
  1461. _rebuildUpdate: function()
  1462. {
  1463. if (this._rebuildUpdateInProgress) {
  1464. this._lastNodeForInnerRebuild = this.node;
  1465. return;
  1466. }
  1467.  
  1468. var node = this._validateNode();
  1469. if (!node)
  1470. return;
  1471.  
  1472. this._rebuildUpdateInProgress = true;
  1473.  
  1474. var resultStyles = {};
  1475.  
  1476. function stylesCallback(matchedResult)
  1477. {
  1478. delete this._rebuildUpdateInProgress;
  1479.  
  1480. var lastNodeForRebuild = this._lastNodeForInnerRebuild;
  1481. if (lastNodeForRebuild) {
  1482. delete this._lastNodeForInnerRebuild;
  1483. if (lastNodeForRebuild !== this.node) {
  1484. this._rebuildUpdate();
  1485. return;
  1486. }
  1487. }
  1488.  
  1489. if (matchedResult && this.node === node) {
  1490. resultStyles.matchedCSSRules = matchedResult.matchedCSSRules;
  1491. resultStyles.pseudoElements = matchedResult.pseudoElements;
  1492. resultStyles.inherited = matchedResult.inherited;
  1493. this._innerRebuildUpdate(node, resultStyles);
  1494. }
  1495.  
  1496. if (lastNodeForRebuild) {
  1497.  
  1498. this._rebuildUpdate();
  1499. return;
  1500. }
  1501. }
  1502.  
  1503. function inlineCallback(inlineStyle, attributesStyle)
  1504. {
  1505. resultStyles.inlineStyle = inlineStyle;
  1506. resultStyles.attributesStyle = attributesStyle;
  1507. }
  1508.  
  1509. function computedCallback(computedStyle)
  1510. {
  1511. resultStyles.computedStyle = computedStyle;
  1512. }
  1513.  
  1514. if (this._computedStylePane.expanded)
  1515. WebInspector.cssModel.getComputedStyleAsync(node.id, computedCallback.bind(this));
  1516. WebInspector.cssModel.getInlineStylesAsync(node.id, inlineCallback.bind(this));
  1517. WebInspector.cssModel.getMatchedStylesAsync(node.id, true, true, stylesCallback.bind(this));
  1518. },
  1519.  
  1520.  
  1521. _validateNode: function(userCallback)
  1522. {
  1523. if (!this.node) {
  1524. this._sectionsContainer.removeChildren();
  1525. this._computedStylePane.bodyElement.removeChildren();
  1526. this.sections = {};
  1527. if (userCallback)
  1528. userCallback();
  1529. return null;
  1530. }
  1531. return this.node;
  1532. },
  1533.  
  1534. _styleSheetOrMediaQueryResultChanged: function()
  1535. {
  1536. if (this._userOperation || this._isEditingStyle)
  1537. return;
  1538.  
  1539. this._rebuildUpdate();
  1540. },
  1541.  
  1542. _attributeChanged: function(event)
  1543. {
  1544.  
  1545.  
  1546. if (this._isEditingStyle || this._userOperation)
  1547. return;
  1548.  
  1549. if (!this._canAffectCurrentStyles(event.data.node))
  1550. return;
  1551.  
  1552. this._rebuildUpdate();
  1553. },
  1554.  
  1555. _canAffectCurrentStyles: function(node)
  1556. {
  1557. return this.node && (this.node === node || node.parentNode === this.node.parentNode || node.isAncestor(this.node));
  1558. },
  1559.  
  1560. _innerRefreshUpdate: function(node, computedStyle, editedSection)
  1561. {
  1562. for (var pseudoId in this.sections) {
  1563. var styleRules = this._refreshStyleRules(this.sections[pseudoId], computedStyle);
  1564. var usedProperties = {};
  1565. this._markUsedProperties(styleRules, usedProperties);
  1566. this._refreshSectionsForStyleRules(styleRules, usedProperties, editedSection);
  1567. }
  1568. if (computedStyle)
  1569. this.sections[0][0].rebuildComputedTrace(this.sections[0]);
  1570.  
  1571. this._nodeStylesUpdatedForTest(node, false);
  1572. },
  1573.  
  1574. _innerRebuildUpdate: function(node, styles)
  1575. {
  1576. this._sectionsContainer.removeChildren();
  1577. this._computedStylePane.bodyElement.removeChildren();
  1578. this._linkifier.reset();
  1579.  
  1580. var styleRules = this._rebuildStyleRules(node, styles);
  1581. var usedProperties = {};
  1582. this._markUsedProperties(styleRules, usedProperties);
  1583. this.sections[0] = this._rebuildSectionsForStyleRules(styleRules, usedProperties, 0, null);
  1584. var anchorElement = this.sections[0].inheritedPropertiesSeparatorElement;
  1585.  
  1586. if (styles.computedStyle)        
  1587. this.sections[0][0].rebuildComputedTrace(this.sections[0]);
  1588.  
  1589. for (var i = 0; i < styles.pseudoElements.length; ++i) {
  1590. var pseudoElementCSSRules = styles.pseudoElements[i];
  1591.  
  1592. styleRules = [];
  1593. var pseudoId = pseudoElementCSSRules.pseudoId;
  1594.  
  1595. var entry = { isStyleSeparator: true, pseudoId: pseudoId };
  1596. styleRules.push(entry);
  1597.  
  1598.  
  1599. for (var j = pseudoElementCSSRules.rules.length - 1; j >= 0; --j) {
  1600. var rule = pseudoElementCSSRules.rules[j];
  1601. styleRules.push({ style: rule.style, selectorText: rule.selectorText, media: rule.media, sourceURL: rule.sourceURL, rule: rule, editable: !!(rule.style && rule.style.id) });
  1602. }
  1603. usedProperties = {};
  1604. this._markUsedProperties(styleRules, usedProperties);
  1605. this.sections[pseudoId] = this._rebuildSectionsForStyleRules(styleRules, usedProperties, pseudoId, anchorElement);
  1606. }
  1607.  
  1608. this._nodeStylesUpdatedForTest(node, true);
  1609. },
  1610.  
  1611. _nodeStylesUpdatedForTest: function(node, rebuild)
  1612. {
  1613.  
  1614. },
  1615.  
  1616. _refreshStyleRules: function(sections, computedStyle)
  1617. {
  1618. var nodeComputedStyle = computedStyle;
  1619. var styleRules = [];
  1620. for (var i = 0; sections && i < sections.length; ++i) {
  1621. var section = sections[i];
  1622. if (section.isBlank)
  1623. continue;
  1624. if (section.computedStyle)
  1625. section.styleRule.style = nodeComputedStyle;
  1626. var styleRule = { section: section, style: section.styleRule.style, computedStyle: section.computedStyle, rule: section.rule, editable: !!(section.styleRule.style && section.styleRule.style.id), isAttribute: section.styleRule.isAttribute, isInherited: section.styleRule.isInherited };
  1627. styleRules.push(styleRule);
  1628. }
  1629. return styleRules;
  1630. },
  1631.  
  1632. _rebuildStyleRules: function(node, styles)
  1633. {
  1634. var nodeComputedStyle = styles.computedStyle;
  1635. this.sections = {};
  1636.  
  1637. var styleRules = [];
  1638.  
  1639. function addAttributesStyle()
  1640. {
  1641. if (!styles.attributesStyle)
  1642. return;
  1643. var attrStyle = { style: styles.attributesStyle, editable: false };
  1644. attrStyle.selectorText = node.nodeNameInCorrectCase() + "[" + WebInspector.UIString("Attributes Style") + "]";
  1645. styleRules.push(attrStyle);
  1646. }
  1647.  
  1648. styleRules.push({ computedStyle: true, selectorText: "", style: nodeComputedStyle, editable: false });
  1649.  
  1650.  
  1651. if (styles.inlineStyle && node.nodeType() === Node.ELEMENT_NODE) {
  1652. var inlineStyle = { selectorText: "element.style", style: styles.inlineStyle, isAttribute: true };
  1653. styleRules.push(inlineStyle);
  1654. }
  1655.  
  1656.  
  1657. if (styles.matchedCSSRules.length)
  1658. styleRules.push({ isStyleSeparator: true, text: WebInspector.UIString("Matched CSS Rules") });
  1659. var addedAttributesStyle;
  1660. for (var i = styles.matchedCSSRules.length - 1; i >= 0; --i) {
  1661. var rule = styles.matchedCSSRules[i];
  1662. if (!WebInspector.settings.showUserAgentStyles.get() && (rule.isUser || rule.isUserAgent))
  1663. continue;
  1664. if ((rule.isUser || rule.isUserAgent) && !addedAttributesStyle) {
  1665.  
  1666. addedAttributesStyle = true;
  1667. addAttributesStyle();
  1668. }
  1669. styleRules.push({ style: rule.style, selectorText: rule.selectorText, media: rule.media, sourceURL: rule.sourceURL, rule: rule, editable: !!(rule.style && rule.style.id) });
  1670. }
  1671.  
  1672. if (!addedAttributesStyle)
  1673. addAttributesStyle();
  1674.  
  1675.  
  1676. var parentNode = node.parentNode;
  1677. function insertInheritedNodeSeparator(node)
  1678. {
  1679. var entry = {};
  1680. entry.isStyleSeparator = true;
  1681. entry.node = node;
  1682. styleRules.push(entry);
  1683. }
  1684.  
  1685. for (var parentOrdinal = 0; parentOrdinal < styles.inherited.length; ++parentOrdinal) {
  1686. var parentStyles = styles.inherited[parentOrdinal];
  1687. var separatorInserted = false;
  1688. if (parentStyles.inlineStyle) {
  1689. if (this._containsInherited(parentStyles.inlineStyle)) {
  1690. var inlineStyle = { selectorText: WebInspector.UIString("Style Attribute"), style: parentStyles.inlineStyle, isAttribute: true, isInherited: true, parentNode: parentNode };
  1691. if (!separatorInserted) {
  1692. insertInheritedNodeSeparator(parentNode);
  1693. separatorInserted = true;
  1694. }
  1695. styleRules.push(inlineStyle);
  1696. }
  1697. }
  1698.  
  1699. for (var i = parentStyles.matchedCSSRules.length - 1; i >= 0; --i) {
  1700. var rulePayload = parentStyles.matchedCSSRules[i];
  1701. if (!this._containsInherited(rulePayload.style))
  1702. continue;
  1703. var rule = rulePayload;
  1704. if (!WebInspector.settings.showUserAgentStyles.get() && (rule.isUser || rule.isUserAgent))
  1705. continue;
  1706.  
  1707. if (!separatorInserted) {
  1708. insertInheritedNodeSeparator(parentNode);
  1709. separatorInserted = true;
  1710. }
  1711. styleRules.push({ style: rule.style, selectorText: rule.selectorText, media: rule.media, sourceURL: rule.sourceURL, rule: rule, isInherited: true, parentNode: parentNode, editable: !!(rule.style && rule.style.id) });
  1712. }
  1713. parentNode = parentNode.parentNode;
  1714. }
  1715. return styleRules;
  1716. },
  1717.  
  1718. _markUsedProperties: function(styleRules, usedProperties)
  1719. {
  1720. var foundImportantProperties = {};
  1721. var propertyToEffectiveRule = {};
  1722. for (var i = 0; i < styleRules.length; ++i) {
  1723. var styleRule = styleRules[i];
  1724. if (styleRule.computedStyle || styleRule.isStyleSeparator)
  1725. continue;
  1726. if (styleRule.section && styleRule.section.noAffect)
  1727. continue;
  1728.  
  1729. styleRule.usedProperties = {};
  1730.  
  1731. var style = styleRule.style;
  1732. var allProperties = style.allProperties;
  1733. for (var j = 0; j < allProperties.length; ++j) {
  1734. var property = allProperties[j];
  1735. if (!property.isLive || !property.parsedOk)
  1736. continue;
  1737.  
  1738. var canonicalName = WebInspector.StylesSidebarPane.canonicalPropertyName(property.name);
  1739.  
  1740. if (styleRule.isInherited && !WebInspector.CSSKeywordCompletions.InheritedProperties[canonicalName])
  1741. continue;
  1742.  
  1743. if (foundImportantProperties.hasOwnProperty(canonicalName))
  1744. continue;
  1745.  
  1746. var isImportant = property.priority.length;
  1747. if (!isImportant && usedProperties.hasOwnProperty(canonicalName))
  1748. continue;
  1749.  
  1750. if (isImportant) {
  1751. foundImportantProperties[canonicalName] = true;
  1752. if (propertyToEffectiveRule.hasOwnProperty(canonicalName))
  1753. delete propertyToEffectiveRule[canonicalName].usedProperties[canonicalName];
  1754. }
  1755.  
  1756. styleRule.usedProperties[canonicalName] = true;
  1757. usedProperties[canonicalName] = true;
  1758. propertyToEffectiveRule[canonicalName] = styleRule;
  1759. }
  1760. }
  1761. },
  1762.  
  1763. _refreshSectionsForStyleRules: function(styleRules, usedProperties, editedSection)
  1764. {
  1765.  
  1766. for (var i = 0; i < styleRules.length; ++i) {
  1767. var styleRule = styleRules[i];
  1768. var section = styleRule.section;
  1769. if (styleRule.computedStyle) {
  1770. section._usedProperties = usedProperties;
  1771. section.update();
  1772. } else {
  1773. section._usedProperties = styleRule.usedProperties;
  1774. section.update(section === editedSection);
  1775. }
  1776. }
  1777. },
  1778.  
  1779. _rebuildSectionsForStyleRules: function(styleRules, usedProperties, pseudoId, anchorElement)
  1780. {
  1781.  
  1782. var sections = [];
  1783. var lastWasSeparator = true;
  1784. for (var i = 0; i < styleRules.length; ++i) {
  1785. var styleRule = styleRules[i];
  1786. if (styleRule.isStyleSeparator) {
  1787. var separatorElement = document.createElement("div");
  1788. separatorElement.className = "sidebar-separator";
  1789. if (styleRule.node) {
  1790. var link = WebInspector.DOMPresentationUtils.linkifyNodeReference(styleRule.node);
  1791. separatorElement.appendChild(document.createTextNode(WebInspector.UIString("Inherited from") + " "));
  1792. separatorElement.appendChild(link);
  1793. if (!sections.inheritedPropertiesSeparatorElement)
  1794. sections.inheritedPropertiesSeparatorElement = separatorElement;
  1795. } else if ("pseudoId" in styleRule) {
  1796. var pseudoName = WebInspector.StylesSidebarPane.PseudoIdNames[styleRule.pseudoId];
  1797. if (pseudoName)
  1798. separatorElement.textContent = WebInspector.UIString("Pseudo ::%s element", pseudoName);
  1799. else
  1800. separatorElement.textContent = WebInspector.UIString("Pseudo element");
  1801. } else
  1802. separatorElement.textContent = styleRule.text;
  1803. this._sectionsContainer.insertBefore(separatorElement, anchorElement);
  1804. lastWasSeparator = true;
  1805. continue;
  1806. }
  1807. var computedStyle = styleRule.computedStyle;
  1808.  
  1809.  
  1810. var editable = styleRule.editable;
  1811. if (typeof editable === "undefined")
  1812. editable = true;
  1813.  
  1814. if (computedStyle)
  1815. var section = new WebInspector.ComputedStylePropertiesSection(this, styleRule, usedProperties);
  1816. else {
  1817. var section = new WebInspector.StylePropertiesSection(this, styleRule, editable, styleRule.isInherited, lastWasSeparator);
  1818. section._markSelectorMatches();
  1819. }
  1820. section.expanded = true;
  1821.  
  1822. if (computedStyle) {
  1823. this._computedStylePane.bodyElement.appendChild(section.element);
  1824. lastWasSeparator = true;
  1825. } else {
  1826. this._sectionsContainer.insertBefore(section.element, anchorElement);
  1827. lastWasSeparator = false;
  1828. }
  1829. sections.push(section);
  1830. }
  1831. return sections;
  1832. },
  1833.  
  1834. _containsInherited: function(style)
  1835. {
  1836. var properties = style.allProperties;
  1837. for (var i = 0; i < properties.length; ++i) {
  1838. var property = properties[i];
  1839.  
  1840. if (property.isLive && property.name in WebInspector.CSSKeywordCompletions.InheritedProperties)
  1841. return true;
  1842. }
  1843. return false;
  1844. },
  1845.  
  1846. _colorFormatSettingChanged: function(event)
  1847. {
  1848. this._updateColorFormatFilter();
  1849. for (var pseudoId in this.sections) {
  1850. var sections = this.sections[pseudoId];
  1851. for (var i = 0; i < sections.length; ++i)
  1852. sections[i].update(true);
  1853. }
  1854. },
  1855.  
  1856. _updateColorFormatFilter: function()
  1857. {
  1858.  
  1859. var selectedIndex = 0;
  1860. var value = WebInspector.settings.colorFormat.get();
  1861. var options = this.settingsSelectElement.options;
  1862. for (var i = 0; i < options.length; ++i) {
  1863. if (options[i].value === value) {
  1864. selectedIndex = i;
  1865. break;
  1866. }
  1867. }
  1868. this.settingsSelectElement.selectedIndex = selectedIndex;
  1869. },
  1870.  
  1871. _changeSetting: function(event)
  1872. {
  1873. var options = this.settingsSelectElement.options;
  1874. var selectedOption = options[this.settingsSelectElement.selectedIndex];
  1875. WebInspector.settings.colorFormat.set(selectedOption.value);
  1876. },
  1877.  
  1878. _createNewRule: function(event)
  1879. {
  1880. event.consume();
  1881. this.expanded = true;
  1882. this.addBlankSection().startEditingSelector();
  1883. },
  1884.  
  1885. addBlankSection: function()
  1886. {
  1887. var blankSection = new WebInspector.BlankStylePropertiesSection(this, this.node ? this.node.appropriateSelectorFor(true) : "");
  1888.  
  1889. var elementStyleSection = this.sections[0][1];
  1890. this._sectionsContainer.insertBefore(blankSection.element, elementStyleSection.element.nextSibling);
  1891.  
  1892. this.sections[0].splice(2, 0, blankSection);
  1893.  
  1894. return blankSection;
  1895. },
  1896.  
  1897. removeSection: function(section)
  1898. {
  1899. for (var pseudoId in this.sections) {
  1900. var sections = this.sections[pseudoId];
  1901. var index = sections.indexOf(section);
  1902. if (index === -1)
  1903. continue;
  1904. sections.splice(index, 1);
  1905. if (section.element.parentNode)
  1906. section.element.parentNode.removeChild(section.element);
  1907. }
  1908. },
  1909.  
  1910. _toggleElementStatePane: function(event)
  1911. {
  1912. event.consume();
  1913. if (!this._elementStateButton.hasStyleClass("toggled")) {
  1914. this.expand();
  1915. this._elementStateButton.addStyleClass("toggled");
  1916. this._elementStatePane.addStyleClass("expanded");
  1917. } else {
  1918. this._elementStateButton.removeStyleClass("toggled");
  1919. this._elementStatePane.removeStyleClass("expanded");
  1920. }
  1921. },
  1922.  
  1923. _createElementStatePane: function()
  1924. {
  1925. this._elementStatePane = document.createElement("div");
  1926. this._elementStatePane.className = "styles-element-state-pane source-code";
  1927. var table = document.createElement("table");
  1928.  
  1929. var inputs = [];
  1930. this._elementStatePane.inputs = inputs;
  1931.  
  1932. function clickListener(event)
  1933. {
  1934. var node = this._validateNode();
  1935. if (!node)
  1936. return;
  1937. this._setPseudoClassCallback(node.id, event.target.state, event.target.checked);
  1938. }
  1939.  
  1940. function createCheckbox(state)
  1941. {
  1942. var td = document.createElement("td");
  1943. var label = document.createElement("label");
  1944. var input = document.createElement("input");
  1945. input.type = "checkbox";
  1946. input.state = state;
  1947. input.addEventListener("click", clickListener.bind(this), false);
  1948. inputs.push(input);
  1949. label.appendChild(input);
  1950. label.appendChild(document.createTextNode(":" + state));
  1951. td.appendChild(label);
  1952. return td;
  1953. }
  1954.  
  1955. var tr = document.createElement("tr");
  1956. tr.appendChild(createCheckbox.call(this, "active"));
  1957. tr.appendChild(createCheckbox.call(this, "hover"));
  1958. table.appendChild(tr);
  1959.  
  1960. tr = document.createElement("tr");
  1961. tr.appendChild(createCheckbox.call(this, "focus"));
  1962. tr.appendChild(createCheckbox.call(this, "visited"));
  1963. table.appendChild(tr);
  1964.  
  1965. this._elementStatePane.appendChild(table);
  1966. },
  1967.  
  1968. _showUserAgentStylesSettingChanged: function()
  1969. {
  1970. this._rebuildUpdate();
  1971. },
  1972.  
  1973. willHide: function()
  1974. {
  1975. this._spectrumHelper.hide();
  1976. },
  1977.  
  1978. __proto__: WebInspector.SidebarPane.prototype
  1979. }
  1980.  
  1981.  
  1982. WebInspector.ComputedStyleSidebarPane = function()
  1983. {
  1984. WebInspector.SidebarPane.call(this, WebInspector.UIString("Computed Style"));
  1985. var showInheritedCheckbox = new WebInspector.Checkbox(WebInspector.UIString("Show inherited"), "sidebar-pane-subtitle");
  1986. this.titleElement.appendChild(showInheritedCheckbox.element);
  1987.  
  1988. if (WebInspector.settings.showInheritedComputedStyleProperties.get()) {
  1989. this.bodyElement.addStyleClass("show-inherited");
  1990. showInheritedCheckbox.checked = true;
  1991. }
  1992.  
  1993. function showInheritedToggleFunction(event)
  1994. {
  1995. WebInspector.settings.showInheritedComputedStyleProperties.set(showInheritedCheckbox.checked);
  1996. if (WebInspector.settings.showInheritedComputedStyleProperties.get())
  1997. this.bodyElement.addStyleClass("show-inherited");
  1998. else
  1999. this.bodyElement.removeStyleClass("show-inherited");
  2000. }
  2001.  
  2002. showInheritedCheckbox.addEventListener(showInheritedToggleFunction.bind(this));
  2003. }
  2004.  
  2005. WebInspector.ComputedStyleSidebarPane.prototype = {
  2006.  
  2007.  
  2008. expand: function()
  2009. {
  2010. function callback()
  2011. {
  2012. WebInspector.SidebarPane.prototype.expand.call(this);
  2013. }
  2014.  
  2015. this._stylesSidebarPane._refreshUpdate(null, true, callback.bind(this));
  2016. },
  2017.  
  2018. __proto__: WebInspector.SidebarPane.prototype
  2019. }
  2020.  
  2021.  
  2022. WebInspector.StylePropertiesSection = function(parentPane, styleRule, editable, isInherited, isFirstSection)
  2023. {
  2024. WebInspector.PropertiesSection.call(this, "");
  2025. this.element.className = "styles-section matched-styles monospace" + (isFirstSection ? " first-styles-section" : "");
  2026.  
  2027. if (styleRule.media) {
  2028. for (var i = styleRule.media.length - 1; i >= 0; --i) {
  2029. var media = styleRule.media[i];
  2030. var mediaDataElement = this.titleElement.createChild("div", "media");
  2031. var mediaText;
  2032. switch (media.source) {
  2033. case WebInspector.CSSMedia.Source.LINKED_SHEET:
  2034. case WebInspector.CSSMedia.Source.INLINE_SHEET:
  2035. mediaText = "media=\"" + media.text + "\"";
  2036. break;
  2037. case WebInspector.CSSMedia.Source.MEDIA_RULE:
  2038. mediaText = "@media " + media.text;
  2039. break;
  2040. case WebInspector.CSSMedia.Source.IMPORT_RULE:
  2041. mediaText = "@import " + media.text;
  2042. break;
  2043. }
  2044.  
  2045. if (media.sourceURL) {
  2046. var refElement = mediaDataElement.createChild("div", "subtitle");
  2047. var lineNumber = media.sourceLine < 0 ? undefined : media.sourceLine;
  2048. var anchor = WebInspector.linkifyResourceAsNode(media.sourceURL, lineNumber, "subtitle", media.sourceURL + (isNaN(lineNumber) ? "" : (":" + (lineNumber + 1))));
  2049. anchor.preferredPanel = "scripts";
  2050. anchor.style.float = "right";
  2051. refElement.appendChild(anchor);
  2052. }
  2053.  
  2054. var mediaTextElement = mediaDataElement.createChild("span");
  2055. mediaTextElement.textContent = mediaText;
  2056. mediaTextElement.title = media.text;
  2057. }
  2058. }
  2059.  
  2060. var selectorContainer = document.createElement("div");
  2061. this._selectorElement = document.createElement("span");
  2062. this._selectorElement.textContent = styleRule.selectorText;
  2063. selectorContainer.appendChild(this._selectorElement);
  2064.  
  2065. var openBrace = document.createElement("span");
  2066. openBrace.textContent = " {";
  2067. selectorContainer.appendChild(openBrace);
  2068. selectorContainer.addEventListener("mousedown", this._handleEmptySpaceMouseDown.bind(this), false);
  2069. selectorContainer.addEventListener("click", this._handleSelectorContainerClick.bind(this), false);
  2070.  
  2071. var closeBrace = document.createElement("div");
  2072. closeBrace.textContent = "}";
  2073. this.element.appendChild(closeBrace);
  2074.  
  2075. this._selectorElement.addEventListener("click", this._handleSelectorClick.bind(this), false);
  2076. this.element.addEventListener("mousedown", this._handleEmptySpaceMouseDown.bind(this), false);
  2077. this.element.addEventListener("click", this._handleEmptySpaceClick.bind(this), false);
  2078.  
  2079. this._parentPane = parentPane;
  2080. this.styleRule = styleRule;
  2081. this.rule = this.styleRule.rule;
  2082. this.editable = editable;
  2083. this.isInherited = isInherited;
  2084.  
  2085. if (this.rule) {
  2086.  
  2087. if (this.rule.isUserAgent || this.rule.isUser)
  2088. this.editable = false;
  2089. this.titleElement.addStyleClass("styles-selector");
  2090. }
  2091.  
  2092. this._usedProperties = styleRule.usedProperties;
  2093.  
  2094. this._selectorRefElement = document.createElement("div");
  2095. this._selectorRefElement.className = "subtitle";
  2096. this._selectorRefElement.appendChild(this._createRuleOriginNode());
  2097. selectorContainer.insertBefore(this._selectorRefElement, selectorContainer.firstChild);
  2098. this.titleElement.appendChild(selectorContainer);
  2099. this._selectorContainer = selectorContainer;
  2100.  
  2101. if (isInherited)
  2102. this.element.addStyleClass("show-inherited"); 
  2103.  
  2104. if (!this.editable)
  2105. this.element.addStyleClass("read-only");
  2106. }
  2107.  
  2108. WebInspector.StylePropertiesSection.prototype = {
  2109. get pane()
  2110. {
  2111. return this._parentPane;
  2112. },
  2113.  
  2114. collapse: function(dontRememberState)
  2115. {
  2116.  
  2117. },
  2118.  
  2119. isPropertyInherited: function(propertyName)
  2120. {
  2121. if (this.isInherited) {
  2122.  
  2123.  
  2124. return !(propertyName in WebInspector.CSSKeywordCompletions.InheritedProperties);
  2125. }
  2126. return false;
  2127. },
  2128.  
  2129.  
  2130. isPropertyOverloaded: function(propertyName, isShorthand)
  2131. {
  2132. if (!this._usedProperties || this.noAffect)
  2133. return false;
  2134.  
  2135. if (this.isInherited && !(propertyName in WebInspector.CSSKeywordCompletions.InheritedProperties)) {
  2136.  
  2137. return false;
  2138. }
  2139.  
  2140. var canonicalName = WebInspector.StylesSidebarPane.canonicalPropertyName(propertyName);
  2141. var used = (canonicalName in this._usedProperties);
  2142. if (used || !isShorthand)
  2143. return !used;
  2144.  
  2145.  
  2146.  
  2147. var longhandProperties = this.styleRule.style.longhandProperties(propertyName);
  2148. for (var j = 0; j < longhandProperties.length; ++j) {
  2149. var individualProperty = longhandProperties[j];
  2150. if (WebInspector.StylesSidebarPane.canonicalPropertyName(individualProperty.name) in this._usedProperties)
  2151. return false;
  2152. }
  2153.  
  2154. return true;
  2155. },
  2156.  
  2157. nextEditableSibling: function()
  2158. {
  2159. var curSection = this;
  2160. do {
  2161. curSection = curSection.nextSibling;
  2162. } while (curSection && !curSection.editable);
  2163.  
  2164. if (!curSection) {
  2165. curSection = this.firstSibling;
  2166. while (curSection && !curSection.editable)
  2167. curSection = curSection.nextSibling;
  2168. }
  2169.  
  2170. return (curSection && curSection.editable) ? curSection : null;
  2171. },
  2172.  
  2173. previousEditableSibling: function()
  2174. {
  2175. var curSection = this;
  2176. do {
  2177. curSection = curSection.previousSibling;
  2178. } while (curSection && !curSection.editable);
  2179.  
  2180. if (!curSection) {
  2181. curSection = this.lastSibling;
  2182. while (curSection && !curSection.editable)
  2183. curSection = curSection.previousSibling;
  2184. }
  2185.  
  2186. return (curSection && curSection.editable) ? curSection : null;
  2187. },
  2188.  
  2189. update: function(full)
  2190. {
  2191. if (this.styleRule.selectorText)
  2192. this._selectorElement.textContent = this.styleRule.selectorText;
  2193. this._markSelectorMatches();
  2194. if (full) {
  2195. this.propertiesTreeOutline.removeChildren();
  2196. this.populated = false;
  2197. } else {
  2198. var child = this.propertiesTreeOutline.children[0];
  2199. while (child) {
  2200. child.overloaded = this.isPropertyOverloaded(child.name, child.isShorthand);
  2201. child = child.traverseNextTreeElement(false, null, true);
  2202. }
  2203. }
  2204. this.afterUpdate();
  2205. },
  2206.  
  2207. afterUpdate: function()
  2208. {
  2209. if (this._afterUpdate) {
  2210. this._afterUpdate(this);
  2211. delete this._afterUpdate;
  2212. }
  2213. },
  2214.  
  2215. onpopulate: function()
  2216. {
  2217. var style = this.styleRule.style;
  2218. var allProperties = style.allProperties;
  2219. this.uniqueProperties = [];
  2220.  
  2221. var styleHasEditableSource = this.editable && !!style.range;
  2222. if (styleHasEditableSource) {
  2223. for (var i = 0; i < allProperties.length; ++i) {
  2224. var property = allProperties[i];
  2225. this.uniqueProperties.push(property);
  2226. if (property.styleBased)
  2227. continue;
  2228.  
  2229. var isShorthand = !!WebInspector.CSSCompletions.cssPropertiesMetainfo.longhands(property.name);
  2230. var inherited = this.isPropertyInherited(property.name);
  2231. var overloaded = property.inactive || this.isPropertyOverloaded(property.name);
  2232. var item = new WebInspector.StylePropertyTreeElement(this, this._parentPane, this.styleRule, style, property, isShorthand, inherited, overloaded);
  2233. this.propertiesTreeOutline.appendChild(item);
  2234. }
  2235. return;
  2236. }
  2237.  
  2238. var generatedShorthands = {};
  2239.  
  2240. for (var i = 0; i < allProperties.length; ++i) {
  2241. var property = allProperties[i];
  2242. this.uniqueProperties.push(property);
  2243. var isShorthand = !!WebInspector.CSSCompletions.cssPropertiesMetainfo.longhands(property.name);
  2244.  
  2245.  
  2246. var shorthands = isShorthand ? null : WebInspector.CSSCompletions.cssPropertiesMetainfo.shorthands(property.name);
  2247. var shorthandPropertyAvailable = false;
  2248. for (var j = 0; shorthands && !shorthandPropertyAvailable && j < shorthands.length; ++j) {
  2249. var shorthand = shorthands[j];
  2250. if (shorthand in generatedShorthands) {
  2251. shorthandPropertyAvailable = true;
  2252. continue;  
  2253. }
  2254. if (style.getLiveProperty(shorthand)) {
  2255. shorthandPropertyAvailable = true;
  2256. continue;  
  2257. }
  2258. if (!style.shorthandValue(shorthand)) {
  2259. shorthandPropertyAvailable = false;
  2260. continue;  
  2261. }
  2262.  
  2263.  
  2264. var shorthandProperty = new WebInspector.CSSProperty(style, style.allProperties.length, shorthand, style.shorthandValue(shorthand), "", "style", true, true, undefined);
  2265. var overloaded = property.inactive || this.isPropertyOverloaded(property.name, true);
  2266. var item = new WebInspector.StylePropertyTreeElement(this, this._parentPane, this.styleRule, style, shorthandProperty,    true,   false, overloaded);
  2267. this.propertiesTreeOutline.appendChild(item);
  2268. generatedShorthands[shorthand] = shorthandProperty;
  2269. shorthandPropertyAvailable = true;
  2270. }
  2271. if (shorthandPropertyAvailable)
  2272. continue;  
  2273.  
  2274. var inherited = this.isPropertyInherited(property.name);
  2275. var overloaded = property.inactive || this.isPropertyOverloaded(property.name, isShorthand);
  2276. var item = new WebInspector.StylePropertyTreeElement(this, this._parentPane, this.styleRule, style, property, isShorthand, inherited, overloaded);
  2277. this.propertiesTreeOutline.appendChild(item);
  2278. }
  2279. },
  2280.  
  2281. findTreeElementWithName: function(name)
  2282. {
  2283. var treeElement = this.propertiesTreeOutline.children[0];
  2284. while (treeElement) {
  2285. if (treeElement.name === name)
  2286. return treeElement;
  2287. treeElement = treeElement.traverseNextTreeElement(true, null, true);
  2288. }
  2289. return null;
  2290. },
  2291.  
  2292. _markSelectorMatches: function()
  2293. {
  2294. var rule = this.styleRule.rule;
  2295. if (!rule)
  2296. return;
  2297.  
  2298. var matchingSelectors = rule.matchingSelectors;
  2299.  
  2300. if (this.noAffect || matchingSelectors)
  2301. this._selectorElement.className = "selector";
  2302. if (!matchingSelectors)
  2303. return;
  2304.  
  2305. var selectors = rule.selectors;
  2306. var fragment = document.createDocumentFragment();
  2307. var currentMatch = 0;
  2308. for (var i = 0, lastSelectorIndex = selectors.length - 1; i <= lastSelectorIndex ; ++i) {
  2309. var selectorNode;
  2310. var textNode = document.createTextNode(selectors[i]);
  2311. if (matchingSelectors[currentMatch] === i) {
  2312. ++currentMatch;
  2313. selectorNode = document.createElement("span");
  2314. selectorNode.className = "selector-matches";
  2315. selectorNode.appendChild(textNode);
  2316. } else
  2317. selectorNode = textNode;
  2318.  
  2319. fragment.appendChild(selectorNode);
  2320. if (i !== lastSelectorIndex)
  2321. fragment.appendChild(document.createTextNode(", "));
  2322. }
  2323.  
  2324. this._selectorElement.removeChildren();
  2325. this._selectorElement.appendChild(fragment);
  2326. },
  2327.  
  2328. _checkWillCancelEditing: function()
  2329. {
  2330. var willCauseCancelEditing = this._willCauseCancelEditing;
  2331. delete this._willCauseCancelEditing;
  2332. return willCauseCancelEditing;
  2333. },
  2334.  
  2335. _handleSelectorContainerClick: function(event)
  2336. {
  2337. if (this._checkWillCancelEditing() || !this.editable)
  2338. return;
  2339. if (event.target === this._selectorContainer)
  2340. this.addNewBlankProperty(0).startEditing();
  2341. },
  2342.  
  2343.  
  2344. addNewBlankProperty: function(index)
  2345. {
  2346. var style = this.styleRule.style;
  2347. var property = style.newBlankProperty(index);
  2348. var item = new WebInspector.StylePropertyTreeElement(this, this._parentPane, this.styleRule, style, property, false, false, false);
  2349. index = property.index;
  2350. this.propertiesTreeOutline.insertChild(item, index);
  2351. item.listItemElement.textContent = "";
  2352. item._newProperty = true;
  2353. item.updateTitle();
  2354. return item;
  2355. },
  2356.  
  2357. _createRuleOriginNode: function()
  2358. {
  2359.  
  2360. function linkifyUncopyable(url, line)
  2361. {
  2362. var link = WebInspector.linkifyResourceAsNode(url, line, "", url + ":" + (line + 1));
  2363. link.preferredPanel = "scripts";
  2364. link.classList.add("webkit-html-resource-link");
  2365. link.setAttribute("data-uncopyable", link.textContent);
  2366. link.textContent = "";
  2367. return link;
  2368. }
  2369.  
  2370. if (this.styleRule.sourceURL)
  2371. return this._parentPane._linkifier.linkifyCSSRuleLocation(this.rule) || linkifyUncopyable(this.styleRule.sourceURL, this.rule.sourceLine);
  2372.  
  2373. if (!this.rule)
  2374. return document.createTextNode("");
  2375.  
  2376. var origin = "";
  2377. if (this.rule.isUserAgent)
  2378. return document.createTextNode(WebInspector.UIString("user agent stylesheet"));
  2379. if (this.rule.isUser)
  2380. return document.createTextNode(WebInspector.UIString("user stylesheet"));
  2381. if (this.rule.isViaInspector) {
  2382. var element = document.createElement("span");
  2383.  
  2384. function callback(resource)
  2385. {
  2386. if (resource)
  2387. element.appendChild(linkifyUncopyable(resource.url, this.rule.sourceLine));
  2388. else
  2389. element.textContent = WebInspector.UIString("via inspector");
  2390. }
  2391. WebInspector.cssModel.getViaInspectorResourceForRule(this.rule, callback.bind(this));
  2392. return element;
  2393. }
  2394. },
  2395.  
  2396. _handleEmptySpaceMouseDown: function(event)
  2397. {
  2398. this._willCauseCancelEditing = this._parentPane._isEditingStyle;
  2399. },
  2400.  
  2401. _handleEmptySpaceClick: function(event)
  2402. {
  2403. if (!this.editable)
  2404. return;
  2405.  
  2406. if (!window.getSelection().isCollapsed)
  2407. return;
  2408.  
  2409. if (this._checkWillCancelEditing())
  2410. return;
  2411.  
  2412. if (event.target.hasStyleClass("header") || this.element.hasStyleClass("read-only") || event.target.enclosingNodeOrSelfWithClass("media")) {
  2413. event.consume();
  2414. return;
  2415. }
  2416. this.expand();
  2417. this.addNewBlankProperty().startEditing();
  2418. },
  2419.  
  2420. _handleSelectorClick: function(event)
  2421. {
  2422. this._startEditingOnMouseEvent();
  2423. event.consume(true);
  2424. },
  2425.  
  2426. _startEditingOnMouseEvent: function()
  2427. {
  2428. if (!this.editable)
  2429. return;
  2430.  
  2431. if (!this.rule && this.propertiesTreeOutline.children.length === 0) {
  2432. this.expand();
  2433. this.addNewBlankProperty().startEditing();
  2434. return;
  2435. }
  2436.  
  2437. if (!this.rule)
  2438. return;
  2439.  
  2440. this.startEditingSelector();
  2441. },
  2442.  
  2443. startEditingSelector: function()
  2444. {
  2445. var element = this._selectorElement;
  2446. if (WebInspector.isBeingEdited(element))
  2447. return;
  2448.  
  2449. element.scrollIntoViewIfNeeded(false);
  2450. element.textContent = element.textContent; 
  2451.  
  2452. var config = new WebInspector.EditingConfig(this.editingSelectorCommitted.bind(this), this.editingSelectorCancelled.bind(this));
  2453. WebInspector.startEditing(this._selectorElement, config);
  2454.  
  2455. window.getSelection().setBaseAndExtent(element, 0, element, 1);
  2456. },
  2457.  
  2458. _moveEditorFromSelector: function(moveDirection)
  2459. {
  2460. this._markSelectorMatches();
  2461.  
  2462. if (!moveDirection)
  2463. return;
  2464.  
  2465. if (moveDirection === "forward") {
  2466. this.expand();
  2467. var firstChild = this.propertiesTreeOutline.children[0];
  2468. while (firstChild && firstChild.inherited)
  2469. firstChild = firstChild.nextSibling;
  2470. if (!firstChild)
  2471. this.addNewBlankProperty().startEditing();
  2472. else
  2473. firstChild.startEditing(firstChild.nameElement);
  2474. } else {
  2475. var previousSection = this.previousEditableSibling();
  2476. if (!previousSection)
  2477. return;
  2478.  
  2479. previousSection.expand();
  2480. previousSection.addNewBlankProperty().startEditing();
  2481. }
  2482. },
  2483.  
  2484. editingSelectorCommitted: function(element, newContent, oldContent, context, moveDirection)
  2485. {
  2486. if (newContent)
  2487. newContent = newContent.trim();
  2488. if (newContent === oldContent) {
  2489.  
  2490. this._selectorElement.textContent = newContent;
  2491. return this._moveEditorFromSelector(moveDirection);
  2492. }
  2493.  
  2494. var selectedNode = this._parentPane.node;
  2495.  
  2496. function successCallback(newRule, doesAffectSelectedNode)
  2497. {
  2498. if (!doesAffectSelectedNode) {
  2499. this.noAffect = true;
  2500. this.element.addStyleClass("no-affect");
  2501. } else {
  2502. delete this.noAffect;
  2503. this.element.removeStyleClass("no-affect");
  2504. }
  2505.  
  2506. this.rule = newRule;
  2507. this.styleRule = { section: this, style: newRule.style, selectorText: newRule.selectorText, media: newRule.media, sourceURL: newRule.sourceURL, rule: newRule };
  2508.  
  2509. this._parentPane.update(selectedNode);
  2510.  
  2511. finishOperationAndMoveEditor.call(this, moveDirection);
  2512. }
  2513.  
  2514. function finishOperationAndMoveEditor(direction)
  2515. {
  2516. delete this._parentPane._userOperation;
  2517. this._moveEditorFromSelector(direction);
  2518. }
  2519.  
  2520.  
  2521. this._parentPane._userOperation = true;
  2522. WebInspector.cssModel.setRuleSelector(this.rule.id, selectedNode ? selectedNode.id : 0, newContent, successCallback.bind(this), finishOperationAndMoveEditor.bind(this, moveDirection));
  2523. },
  2524.  
  2525. editingSelectorCancelled: function()
  2526. {
  2527.  
  2528.  
  2529. this._markSelectorMatches();
  2530. },
  2531.  
  2532. __proto__: WebInspector.PropertiesSection.prototype
  2533. }
  2534.  
  2535.  
  2536. WebInspector.ComputedStylePropertiesSection = function(parentPane, styleRule, usedProperties)
  2537. {
  2538. WebInspector.PropertiesSection.call(this, "");
  2539. this.headerElement.addStyleClass("hidden");
  2540. this.element.className = "styles-section monospace first-styles-section read-only computed-style";
  2541. this._parentPane = parentPane;
  2542. this.styleRule = styleRule;
  2543. this._usedProperties = usedProperties;
  2544. this._alwaysShowComputedProperties = { "display": true, "height": true, "width": true };
  2545. this.computedStyle = true;
  2546. this._propertyTreeElements = {};
  2547. this._expandedPropertyNames = {};
  2548. }
  2549.  
  2550. WebInspector.ComputedStylePropertiesSection.prototype = {
  2551. get pane()
  2552. {
  2553. return this._parentPane;
  2554. },
  2555.  
  2556. collapse: function(dontRememberState)
  2557. {
  2558.  
  2559. },
  2560.  
  2561. _isPropertyInherited: function(propertyName)
  2562. {
  2563. var canonicalName = WebInspector.StylesSidebarPane.canonicalPropertyName(propertyName);
  2564. return !(canonicalName in this._usedProperties) && !(canonicalName in this._alwaysShowComputedProperties);
  2565. },
  2566.  
  2567. update: function()
  2568. {
  2569. this._expandedPropertyNames = {};
  2570. for (var name in this._propertyTreeElements) {
  2571. if (this._propertyTreeElements[name].expanded)
  2572. this._expandedPropertyNames[name] = true;
  2573. }
  2574. this._propertyTreeElements = {};
  2575. this.propertiesTreeOutline.removeChildren();
  2576. this.populated = false;
  2577. },
  2578.  
  2579. onpopulate: function()
  2580. {
  2581. function sorter(a, b)
  2582. {
  2583. return a.name.localeCompare(b.name);
  2584. }
  2585.  
  2586. var style = this.styleRule.style;
  2587. if (!style)
  2588. return;
  2589.  
  2590. var uniqueProperties = [];
  2591. var allProperties = style.allProperties;
  2592. for (var i = 0; i < allProperties.length; ++i)
  2593. uniqueProperties.push(allProperties[i]);
  2594. uniqueProperties.sort(sorter);
  2595.  
  2596. this._propertyTreeElements = {};
  2597. for (var i = 0; i < uniqueProperties.length; ++i) {
  2598. var property = uniqueProperties[i];
  2599. var inherited = this._isPropertyInherited(property.name);
  2600. var item = new WebInspector.StylePropertyTreeElement(this, this._parentPane, this.styleRule, style, property, false, inherited, false);
  2601. this.propertiesTreeOutline.appendChild(item);
  2602. this._propertyTreeElements[property.name] = item;
  2603. }
  2604. },
  2605.  
  2606. rebuildComputedTrace: function(sections)
  2607. {
  2608. for (var i = 0; i < sections.length; ++i) {
  2609. var section = sections[i];
  2610. if (section.computedStyle || section.isBlank)
  2611. continue;
  2612.  
  2613. for (var j = 0; j < section.uniqueProperties.length; ++j) {
  2614. var property = section.uniqueProperties[j];
  2615. if (property.disabled)
  2616. continue;
  2617. if (section.isInherited && !(property.name in WebInspector.CSSKeywordCompletions.InheritedProperties))
  2618. continue;
  2619.  
  2620. var treeElement = this._propertyTreeElements[property.name];
  2621. if (treeElement) {
  2622. var fragment = document.createDocumentFragment();
  2623. var selector = fragment.createChild("span");
  2624. selector.style.color = "gray";
  2625. selector.textContent = section.styleRule.selectorText;
  2626. fragment.appendChild(document.createTextNode(" - " + property.value + " "));
  2627. var subtitle = fragment.createChild("span");
  2628. subtitle.style.float = "right";
  2629. subtitle.appendChild(section._createRuleOriginNode());
  2630. var childElement = new TreeElement(fragment, null, false);
  2631. treeElement.appendChild(childElement);
  2632. if (property.inactive || section.isPropertyOverloaded(property.name))
  2633. childElement.listItemElement.addStyleClass("overloaded");
  2634. if (!property.parsedOk) {
  2635. childElement.listItemElement.addStyleClass("not-parsed-ok");
  2636. childElement.listItemElement.insertBefore(WebInspector.StylesSidebarPane.createExclamationMark(property.name), childElement.listItemElement.firstChild);
  2637. }
  2638. }
  2639. }
  2640. }
  2641.  
  2642.  
  2643. for (var name in this._expandedPropertyNames) {
  2644. if (name in this._propertyTreeElements)
  2645. this._propertyTreeElements[name].expand();
  2646. }
  2647. },
  2648.  
  2649. __proto__: WebInspector.PropertiesSection.prototype
  2650. }
  2651.  
  2652.  
  2653. WebInspector.BlankStylePropertiesSection = function(parentPane, defaultSelectorText)
  2654. {
  2655. WebInspector.StylePropertiesSection.call(this, parentPane, {selectorText: defaultSelectorText, rule: {isViaInspector: true}}, true, false, false);
  2656. this.element.addStyleClass("blank-section");
  2657. }
  2658.  
  2659. WebInspector.BlankStylePropertiesSection.prototype = {
  2660. get isBlank()
  2661. {
  2662. return !this._normal;
  2663. },
  2664.  
  2665. expand: function()
  2666. {
  2667. if (!this.isBlank)
  2668. WebInspector.StylePropertiesSection.prototype.expand.call(this);
  2669. },
  2670.  
  2671. editingSelectorCommitted: function(element, newContent, oldContent, context, moveDirection)
  2672. {
  2673. if (!this.isBlank) {
  2674. WebInspector.StylePropertiesSection.prototype.editingSelectorCommitted.call(this, element, newContent, oldContent, context, moveDirection);
  2675. return;
  2676. }
  2677.  
  2678. function successCallback(newRule, doesSelectorAffectSelectedNode)
  2679. {
  2680. var styleRule = { section: this, style: newRule.style, selectorText: newRule.selectorText, sourceURL: newRule.sourceURL, rule: newRule };
  2681. this.makeNormal(styleRule);
  2682.  
  2683. if (!doesSelectorAffectSelectedNode) {
  2684. this.noAffect = true;
  2685. this.element.addStyleClass("no-affect");
  2686. }
  2687.  
  2688. this._selectorRefElement.removeChildren();
  2689. this._selectorRefElement.appendChild(this._createRuleOriginNode());
  2690. this.expand();
  2691. if (this.element.parentElement) 
  2692. this._moveEditorFromSelector(moveDirection);
  2693.  
  2694. this._markSelectorMatches();
  2695. delete this._parentPane._userOperation;
  2696. }
  2697.  
  2698. if (newContent)
  2699. newContent = newContent.trim();
  2700. this._parentPane._userOperation = true;
  2701. WebInspector.cssModel.addRule(this.pane.node.id, newContent, successCallback.bind(this), this.editingSelectorCancelled.bind(this));
  2702. },
  2703.  
  2704. editingSelectorCancelled: function()
  2705. {
  2706. delete this._parentPane._userOperation;
  2707. if (!this.isBlank) {
  2708. WebInspector.StylePropertiesSection.prototype.editingSelectorCancelled.call(this);
  2709. return;
  2710. }
  2711.  
  2712. this.pane.removeSection(this);
  2713. },
  2714.  
  2715. makeNormal: function(styleRule)
  2716. {
  2717. this.element.removeStyleClass("blank-section");
  2718. this.styleRule = styleRule;
  2719. this.rule = styleRule.rule;
  2720.  
  2721.  
  2722. this._normal = true;
  2723. },
  2724.  
  2725. __proto__: WebInspector.StylePropertiesSection.prototype
  2726. }
  2727.  
  2728.  
  2729. WebInspector.StylePropertyTreeElement = function(section, parentPane, styleRule, style, property, isShorthand, inherited, overloaded)
  2730. {
  2731. this.section = section;
  2732. this._parentPane = parentPane;
  2733. this._styleRule = styleRule;
  2734. this.style = style;
  2735. this.property = property;
  2736. this.isShorthand = isShorthand;
  2737. this._inherited = inherited;
  2738. this._overloaded = overloaded;
  2739.  
  2740.  
  2741. TreeElement.call(this, "", null, isShorthand);
  2742.  
  2743. this.selectable = false;
  2744. }
  2745.  
  2746. WebInspector.StylePropertyTreeElement.prototype = {
  2747. get inherited()
  2748. {
  2749. return this._inherited;
  2750. },
  2751.  
  2752. set inherited(x)
  2753. {
  2754. if (x === this._inherited)
  2755. return;
  2756. this._inherited = x;
  2757. this.updateState();
  2758. },
  2759.  
  2760. get overloaded()
  2761. {
  2762. return this._overloaded;
  2763. },
  2764.  
  2765. set overloaded(x)
  2766. {
  2767. if (x === this._overloaded)
  2768. return;
  2769. this._overloaded = x;
  2770. this.updateState();
  2771. },
  2772.  
  2773. get disabled()
  2774. {
  2775. return this.property.disabled;
  2776. },
  2777.  
  2778. get name()
  2779. {
  2780. if (!this.disabled || !this.property.text)
  2781. return this.property.name;
  2782.  
  2783. var text = this.property.text;
  2784. var index = text.indexOf(":");
  2785. if (index < 1)
  2786. return this.property.name;
  2787.  
  2788. return text.substring(0, index).trim();
  2789. },
  2790.  
  2791. get priority()
  2792. {
  2793. if (this.disabled)
  2794. return ""; 
  2795. return this.property.priority;
  2796. },
  2797.  
  2798. get value()
  2799. {
  2800. if (!this.disabled || !this.property.text)
  2801. return this.property.value;
  2802.  
  2803. var match = this.property.text.match(/(.*);\s*/);
  2804. if (!match || !match[1])
  2805. return this.property.value;
  2806.  
  2807. var text = match[1];
  2808. var index = text.indexOf(":");
  2809. if (index < 1)
  2810. return this.property.value;
  2811.  
  2812. return text.substring(index + 1).trim();
  2813. },
  2814.  
  2815. get parsedOk()
  2816. {
  2817. return this.property.parsedOk;
  2818. },
  2819.  
  2820. onattach: function()
  2821. {
  2822. this.updateTitle();
  2823. this.listItemElement.addEventListener("mousedown", this._mouseDown.bind(this));
  2824. this.listItemElement.addEventListener("mouseup", this._resetMouseDownElement.bind(this));
  2825. this.listItemElement.addEventListener("click", this._mouseClick.bind(this));
  2826. },
  2827.  
  2828. _mouseDown: function(event)
  2829. {
  2830. if (this._parentPane) {
  2831. this._parentPane._mouseDownTreeElement = this;
  2832. this._parentPane._mouseDownTreeElementIsName = this._isNameElement(event.target);
  2833. this._parentPane._mouseDownTreeElementIsValue = this._isValueElement(event.target);
  2834. }
  2835. },
  2836.  
  2837. _resetMouseDownElement: function()
  2838. {
  2839. if (this._parentPane) {
  2840. delete this._parentPane._mouseDownTreeElement;
  2841. delete this._parentPane._mouseDownTreeElementIsName;
  2842. delete this._parentPane._mouseDownTreeElementIsValue;
  2843. }
  2844. },
  2845.  
  2846. updateTitle: function()
  2847. {
  2848. var value = this.value;
  2849.  
  2850. this.updateState();
  2851.  
  2852. var enabledCheckboxElement;
  2853. if (this.parsedOk) {
  2854. enabledCheckboxElement = document.createElement("input");
  2855. enabledCheckboxElement.className = "enabled-button";
  2856. enabledCheckboxElement.type = "checkbox";
  2857. enabledCheckboxElement.checked = !this.disabled;
  2858. enabledCheckboxElement.addEventListener("click", this.toggleEnabled.bind(this), false);
  2859. }
  2860.  
  2861. var nameElement = document.createElement("span");
  2862. nameElement.className = "webkit-css-property";
  2863. nameElement.textContent = this.name;
  2864. nameElement.title = this.property.propertyText;
  2865. this.nameElement = nameElement;
  2866.  
  2867. this._expandElement = document.createElement("span");
  2868. this._expandElement.className = "expand-element";
  2869.  
  2870. var valueElement = document.createElement("span");
  2871. valueElement.className = "value";
  2872. this.valueElement = valueElement;
  2873.  
  2874. var cf = WebInspector.Color.Format;
  2875.  
  2876. if (value) {
  2877. var self = this;
  2878.  
  2879. function processValue(regex, processor, nextProcessor, valueText)
  2880. {
  2881. var container = document.createDocumentFragment();
  2882.  
  2883. var items = valueText.replace(regex, "\0$1\0").split("\0");
  2884. for (var i = 0; i < items.length; ++i) {
  2885. if ((i % 2) === 0) {
  2886. if (nextProcessor)
  2887. container.appendChild(nextProcessor(items[i]));
  2888. else
  2889. container.appendChild(document.createTextNode(items[i]));
  2890. } else {
  2891. var processedNode = processor(items[i]);
  2892. if (processedNode)
  2893. container.appendChild(processedNode);
  2894. }
  2895. }
  2896.  
  2897. return container;
  2898. }
  2899.  
  2900. function linkifyURL(url)
  2901. {
  2902. var hrefUrl = url;
  2903. var match = hrefUrl.match(/['"]?([^'"]+)/);
  2904. if (match)
  2905. hrefUrl = match[1];
  2906. var container = document.createDocumentFragment();
  2907. container.appendChild(document.createTextNode("url("));
  2908. if (self._styleRule.sourceURL)
  2909. hrefUrl = WebInspector.ParsedURL.completeURL(self._styleRule.sourceURL, hrefUrl);
  2910. else if (self._parentPane.node)
  2911. hrefUrl = self._parentPane.node.resolveURL(hrefUrl);
  2912. var hasResource = !!WebInspector.resourceForURL(hrefUrl);
  2913.  
  2914. container.appendChild(WebInspector.linkifyURLAsNode(hrefUrl, url, undefined, !hasResource));
  2915. container.appendChild(document.createTextNode(")"));
  2916. return container;
  2917. }
  2918.  
  2919. function processColor(text)
  2920. {
  2921. try {
  2922. var color = new WebInspector.Color(text);
  2923. } catch (e) {
  2924. return document.createTextNode(text);
  2925. }
  2926.  
  2927. var format = getFormat();
  2928. var hasSpectrum = self._parentPane;
  2929. var spectrumHelper = hasSpectrum ? self._parentPane._spectrumHelper : null;
  2930. var spectrum = spectrumHelper ? spectrumHelper.spectrum() : null;
  2931.  
  2932. var colorSwatch = new WebInspector.ColorSwatch();
  2933. colorSwatch.setColorString(text);
  2934. colorSwatch.element.addEventListener("click", swatchClick, false);
  2935.  
  2936. var scrollerElement = hasSpectrum ? self._parentPane._computedStylePane.element.parentElement : null;
  2937.  
  2938. function spectrumChanged(e)
  2939. {
  2940. color = e.data;
  2941. var colorString = color.toString();
  2942. spectrum.displayText = colorString;
  2943. colorValueElement.textContent = colorString;
  2944. colorSwatch.setColorString(colorString);
  2945. self.applyStyleText(nameElement.textContent + ": " + valueElement.textContent, false, false, false);
  2946. }
  2947.  
  2948. function spectrumHidden(event)
  2949. {
  2950. scrollerElement.removeEventListener("scroll", repositionSpectrum, false);
  2951. var commitEdit = event.data;
  2952. var propertyText = !commitEdit && self.originalPropertyText ? self.originalPropertyText : (nameElement.textContent + ": " + valueElement.textContent);
  2953. self.applyStyleText(propertyText, true, true, false);
  2954. spectrum.removeEventListener(WebInspector.Spectrum.Events.ColorChanged, spectrumChanged);
  2955. spectrumHelper.removeEventListener(WebInspector.SpectrumPopupHelper.Events.Hidden, spectrumHidden);
  2956.  
  2957. delete self._parentPane._isEditingStyle;
  2958. delete self.originalPropertyText;
  2959. }
  2960.  
  2961. function repositionSpectrum()
  2962. {
  2963. spectrumHelper.reposition(colorSwatch.element);
  2964. }
  2965.  
  2966. function swatchClick(e)
  2967. {
  2968.  
  2969.  
  2970. if (!spectrumHelper || e.shiftKey)
  2971. changeColorDisplay(e);
  2972. else {
  2973. var visible = spectrumHelper.toggle(colorSwatch.element, color, format);
  2974.  
  2975. if (visible) {
  2976. spectrum.displayText = color.toString(format);
  2977. self.originalPropertyText = self.property.propertyText;
  2978. self._parentPane._isEditingStyle = true;
  2979. spectrum.addEventListener(WebInspector.Spectrum.Events.ColorChanged, spectrumChanged);
  2980. spectrumHelper.addEventListener(WebInspector.SpectrumPopupHelper.Events.Hidden, spectrumHidden);
  2981.  
  2982. scrollerElement.addEventListener("scroll", repositionSpectrum, false);
  2983. }
  2984. }
  2985. e.consume(true);
  2986. }
  2987.  
  2988. function getFormat()
  2989. {
  2990. var format;
  2991. var formatSetting = WebInspector.settings.colorFormat.get();
  2992. if (formatSetting === cf.Original)
  2993. format = cf.Original;
  2994. else if (color.nickname)
  2995. format = cf.Nickname;
  2996. else if (formatSetting === cf.RGB)
  2997. format = (color.simple ? cf.RGB : cf.RGBA);
  2998. else if (formatSetting === cf.HSL)
  2999. format = (color.simple ? cf.HSL : cf.HSLA);
  3000. else if (color.simple)
  3001. format = (color.hasShortHex() ? cf.ShortHEX : cf.HEX);
  3002. else
  3003. format = cf.RGBA;
  3004.  
  3005. return format;
  3006. }
  3007.  
  3008. var colorValueElement = document.createElement("span");
  3009. colorValueElement.textContent = color.toString(format);
  3010.  
  3011. function nextFormat(curFormat)
  3012. {
  3013.  
  3014.  
  3015.  
  3016.  
  3017.  
  3018.  
  3019.  
  3020.  
  3021. switch (curFormat) {
  3022. case cf.Original:
  3023. return color.simple ? cf.RGB : cf.RGBA;
  3024.  
  3025. case cf.RGB:
  3026. case cf.RGBA:
  3027. return color.simple ? cf.HSL : cf.HSLA;
  3028.  
  3029. case cf.HSL:
  3030. case cf.HSLA:
  3031. if (color.nickname)
  3032. return cf.Nickname;
  3033. if (color.simple)
  3034. return color.hasShortHex() ? cf.ShortHEX : cf.HEX;
  3035. else
  3036. return cf.Original;
  3037.  
  3038. case cf.ShortHEX:
  3039. return cf.HEX;
  3040.  
  3041. case cf.HEX:
  3042. return cf.Original;
  3043.  
  3044. case cf.Nickname:
  3045. if (color.simple)
  3046. return color.hasShortHex() ? cf.ShortHEX : cf.HEX;
  3047. else
  3048. return cf.Original;
  3049.  
  3050. default:
  3051. return null;
  3052. }
  3053. }
  3054.  
  3055. function changeColorDisplay(event)
  3056. {
  3057. do {
  3058. format = nextFormat(format);
  3059. var currentValue = color.toString(format || "");
  3060. } while (format && currentValue === color.value && format !== cf.Original);
  3061.  
  3062. if (format)
  3063. colorValueElement.textContent = currentValue;
  3064. }
  3065.  
  3066. var container = document.createElement("nobr");
  3067. container.appendChild(colorSwatch.element);
  3068. container.appendChild(colorValueElement);
  3069. return container;
  3070. }
  3071.  
  3072. var colorRegex = /((?:rgb|hsl)a?\([^)]+\)|#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3}|\b\w+\b(?!-))/g;
  3073. var colorProcessor = processValue.bind(window, colorRegex, processColor, null);
  3074.  
  3075. valueElement.appendChild(processValue(/url\(\s*([^)\s]+)\s*\)/g, linkifyURL.bind(this), WebInspector.CSSKeywordCompletions.isColorAwareProperty(self.name) ? colorProcessor : null, value));
  3076. }
  3077.  
  3078. this.listItemElement.removeChildren();
  3079. nameElement.normalize();
  3080. valueElement.normalize();
  3081.  
  3082. if (!this.treeOutline)
  3083. return;
  3084.  
  3085.  
  3086. if (enabledCheckboxElement && this.treeOutline.section && this.parent.root && !this.section.computedStyle)
  3087. this.listItemElement.appendChild(enabledCheckboxElement);
  3088. this.listItemElement.appendChild(nameElement);
  3089. this.listItemElement.appendChild(document.createTextNode(": "));
  3090. this.listItemElement.appendChild(this._expandElement);
  3091. this.listItemElement.appendChild(valueElement);
  3092. this.listItemElement.appendChild(document.createTextNode(";"));
  3093.  
  3094. if (!this.parsedOk) {
  3095.  
  3096. this.hasChildren = false;
  3097. this.listItemElement.addStyleClass("not-parsed-ok");
  3098.  
  3099.  
  3100. this.listItemElement.insertBefore(WebInspector.StylesSidebarPane.createExclamationMark(this.property.name), this.listItemElement.firstChild);
  3101. }
  3102. if (this.property.inactive)
  3103. this.listItemElement.addStyleClass("inactive");
  3104. },
  3105.  
  3106. _updatePane: function(userCallback)
  3107. {
  3108. if (this.treeOutline && this.treeOutline.section && this.treeOutline.section.pane)
  3109. this.treeOutline.section.pane._refreshUpdate(this.treeOutline.section, false, userCallback);
  3110. else  {
  3111. if (userCallback)
  3112. userCallback();
  3113. }
  3114. },
  3115.  
  3116. toggleEnabled: function(event)
  3117. {
  3118. var disabled = !event.target.checked;
  3119.  
  3120. function callback(newStyle)
  3121. {
  3122. if (!newStyle)
  3123. return;
  3124.  
  3125. this.style = newStyle;
  3126. this._styleRule.style = newStyle;
  3127.  
  3128. if (this.treeOutline.section && this.treeOutline.section.pane)
  3129. this.treeOutline.section.pane.dispatchEventToListeners("style property toggled");
  3130.  
  3131. this._updatePane();
  3132.  
  3133. delete this._parentPane._userOperation;
  3134. }
  3135.  
  3136. this._parentPane._userOperation = true;
  3137. this.property.setDisabled(disabled, callback.bind(this));
  3138. event.consume();
  3139. },
  3140.  
  3141. updateState: function()
  3142. {
  3143. if (!this.listItemElement)
  3144. return;
  3145.  
  3146. if (this.style.isPropertyImplicit(this.name) || this.value === "initial")
  3147. this.listItemElement.addStyleClass("implicit");
  3148. else
  3149. this.listItemElement.removeStyleClass("implicit");
  3150.  
  3151. if (this.inherited)
  3152. this.listItemElement.addStyleClass("inherited");
  3153. else
  3154. this.listItemElement.removeStyleClass("inherited");
  3155.  
  3156. if (this.overloaded)
  3157. this.listItemElement.addStyleClass("overloaded");
  3158. else
  3159. this.listItemElement.removeStyleClass("overloaded");
  3160.  
  3161. if (this.disabled)
  3162. this.listItemElement.addStyleClass("disabled");
  3163. else
  3164. this.listItemElement.removeStyleClass("disabled");
  3165. },
  3166.  
  3167. onpopulate: function()
  3168. {
  3169.  
  3170. if (this.children.length || !this.isShorthand)
  3171. return;
  3172.  
  3173. var longhandProperties = this.style.longhandProperties(this.name);
  3174. for (var i = 0; i < longhandProperties.length; ++i) {
  3175. var name = longhandProperties[i].name;
  3176.  
  3177. if (this.treeOutline.section) {
  3178. var inherited = this.treeOutline.section.isPropertyInherited(name);
  3179. var overloaded = this.treeOutline.section.isPropertyOverloaded(name);
  3180. }
  3181.  
  3182. var liveProperty = this.style.getLiveProperty(name);
  3183. if (!liveProperty)
  3184. continue;
  3185.  
  3186. var item = new WebInspector.StylePropertyTreeElement(this.section, this._parentPane, this._styleRule, this.style, liveProperty, false, inherited, overloaded);
  3187. this.appendChild(item);
  3188. }
  3189. },
  3190.  
  3191. restoreNameElement: function()
  3192. {
  3193.  
  3194. if (this.nameElement === this.listItemElement.querySelector(".webkit-css-property"))
  3195. return;
  3196.  
  3197. this.nameElement = document.createElement("span");
  3198. this.nameElement.className = "webkit-css-property";
  3199. this.nameElement.textContent = "";
  3200. this.listItemElement.insertBefore(this.nameElement, this.listItemElement.firstChild);
  3201. },
  3202.  
  3203. _mouseClick: function(event)
  3204. {
  3205. if (!window.getSelection().isCollapsed)
  3206. return;
  3207.  
  3208. event.consume(true);
  3209.  
  3210. if (event.target === this.listItemElement) {
  3211. if (!this.section.editable) 
  3212. return;
  3213.  
  3214. if (this.section._checkWillCancelEditing())
  3215. return;
  3216. this.section.addNewBlankProperty(this.property.index + 1).startEditing();
  3217. return;
  3218. }
  3219.  
  3220. this.startEditing(event.target);
  3221. },
  3222.  
  3223. _isNameElement: function(element)
  3224. {
  3225. return element.enclosingNodeOrSelfWithClass("webkit-css-property") === this.nameElement;
  3226. },
  3227.  
  3228. _isValueElement: function(element)
  3229. {
  3230. return !!element.enclosingNodeOrSelfWithClass("value");
  3231. },
  3232.  
  3233. startEditing: function(selectElement)
  3234. {
  3235.  
  3236. if (this.parent.isShorthand)
  3237. return;
  3238.  
  3239. if (selectElement === this._expandElement)
  3240. return;
  3241.  
  3242. if (this.treeOutline.section && !this.treeOutline.section.editable)
  3243. return;
  3244.  
  3245. if (!selectElement)
  3246. selectElement = this.nameElement; 
  3247. else
  3248. selectElement = selectElement.enclosingNodeOrSelfWithClass("webkit-css-property") || selectElement.enclosingNodeOrSelfWithClass("value");
  3249.  
  3250. var isEditingName = selectElement === this.nameElement;
  3251. if (!isEditingName && selectElement !== this.valueElement) {
  3252.  
  3253. isEditingName = false;
  3254. selectElement = this.valueElement;
  3255. }
  3256.  
  3257. if (WebInspector.isBeingEdited(selectElement))
  3258. return;
  3259.  
  3260. var context = {
  3261. expanded: this.expanded,
  3262. hasChildren: this.hasChildren,
  3263. isEditingName: isEditingName,
  3264. previousContent: selectElement.textContent
  3265. };
  3266.  
  3267.  
  3268. this.hasChildren = false;
  3269.  
  3270. if (selectElement.parentElement)
  3271. selectElement.parentElement.addStyleClass("child-editing");
  3272. selectElement.textContent = selectElement.textContent; 
  3273.  
  3274. function pasteHandler(context, event)
  3275. {
  3276. var data = event.clipboardData.getData("Text");
  3277. if (!data)
  3278. return;
  3279. var colonIdx = data.indexOf(":");
  3280. if (colonIdx < 0)
  3281. return;
  3282. var name = data.substring(0, colonIdx).trim();
  3283. var value = data.substring(colonIdx + 1).trim();
  3284.  
  3285. event.preventDefault();
  3286.  
  3287. if (!("originalName" in context)) {
  3288. context.originalName = this.nameElement.textContent;
  3289. context.originalValue = this.valueElement.textContent;
  3290. }
  3291. this.nameElement.textContent = name;
  3292. this.valueElement.textContent = value;
  3293. this.nameElement.normalize();
  3294. this.valueElement.normalize();
  3295.  
  3296. this.editingCommitted(null, event.target.textContent, context.previousContent, context, "forward");
  3297. }
  3298.  
  3299. function blurListener(context, event)
  3300. {
  3301. var treeElement = this._parentPane._mouseDownTreeElement;
  3302. var moveDirection = "";
  3303. if (treeElement === this) {
  3304. if (isEditingName && this._parentPane._mouseDownTreeElementIsValue)
  3305. moveDirection = "forward";
  3306. if (!isEditingName && this._parentPane._mouseDownTreeElementIsName)
  3307. moveDirection = "backward";
  3308. }
  3309. this.editingCommitted(null, event.target.textContent, context.previousContent, context, moveDirection);
  3310. }
  3311.  
  3312. delete this.originalPropertyText;
  3313.  
  3314. this._parentPane._isEditingStyle = true;
  3315. if (selectElement.parentElement)
  3316. selectElement.parentElement.scrollIntoViewIfNeeded(false);
  3317.  
  3318. var applyItemCallback = !isEditingName ? this._applyFreeFlowStyleTextEdit.bind(this, true) : undefined;
  3319. this._prompt = new WebInspector.StylesSidebarPane.CSSPropertyPrompt(isEditingName ? WebInspector.CSSCompletions.cssPropertiesMetainfo : WebInspector.CSSKeywordCompletions.forProperty(this.nameElement.textContent), this, isEditingName);
  3320. if (applyItemCallback) {
  3321. this._prompt.addEventListener(WebInspector.TextPrompt.Events.ItemApplied, applyItemCallback, this);
  3322. this._prompt.addEventListener(WebInspector.TextPrompt.Events.ItemAccepted, applyItemCallback, this);
  3323. }
  3324. var proxyElement = this._prompt.attachAndStartEditing(selectElement, blurListener.bind(this, context));
  3325.  
  3326. proxyElement.addEventListener("keydown", this.editingNameValueKeyDown.bind(this, context), false);
  3327. if (isEditingName)
  3328. proxyElement.addEventListener("paste", pasteHandler.bind(this, context));
  3329.  
  3330. window.getSelection().setBaseAndExtent(selectElement, 0, selectElement, 1);
  3331. },
  3332.  
  3333. editingNameValueKeyDown: function(context, event)
  3334. {
  3335. if (event.handled)
  3336. return;
  3337.  
  3338. var isEditingName = context.isEditingName;
  3339. var result;
  3340.  
  3341. function shouldCommitValueSemicolon(text, cursorPosition)
  3342. {
  3343.  
  3344. var openQuote = "";
  3345. for (var i = 0; i < cursorPosition; ++i) {
  3346. var ch = text[i];
  3347. if (ch === "\\" && openQuote !== "")
  3348. ++i; 
  3349. else if (!openQuote && (ch === "\"" || ch === "'"))
  3350. openQuote = ch;
  3351. else if (openQuote === ch)
  3352. openQuote = "";
  3353. }
  3354. return !openQuote;
  3355. }
  3356.  
  3357.  
  3358. var isFieldInputTerminated = (event.keyCode === WebInspector.KeyboardShortcut.Keys.Semicolon.code) &&
  3359. (isEditingName ? event.shiftKey : (!event.shiftKey && shouldCommitValueSemicolon(event.target.textContent, event.target.selectionLeftOffset())));
  3360. if (isEnterKey(event) || isFieldInputTerminated) {
  3361.  
  3362. event.preventDefault();
  3363. result = "forward";
  3364. } else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code || event.keyIdentifier === "U+001B")
  3365. result = "cancel";
  3366. else if (!isEditingName && this._newProperty && event.keyCode === WebInspector.KeyboardShortcut.Keys.Backspace.code) {
  3367.  
  3368. var selection = window.getSelection();
  3369. if (selection.isCollapsed && !selection.focusOffset) {
  3370. event.preventDefault();
  3371. result = "backward";
  3372. }
  3373. } else if (event.keyIdentifier === "U+0009") { 
  3374. result = event.shiftKey ? "backward" : "forward";
  3375. event.preventDefault();
  3376. }
  3377.  
  3378. if (result) {
  3379. switch (result) {
  3380. case "cancel":
  3381. this.editingCancelled(null, context);
  3382. break;
  3383. case "forward":
  3384. case "backward":
  3385. this.editingCommitted(null, event.target.textContent, context.previousContent, context, result);
  3386. break;
  3387. }
  3388.  
  3389. event.consume();
  3390. return;
  3391. }
  3392.  
  3393. if (!isEditingName)
  3394. this._applyFreeFlowStyleTextEdit(false);
  3395. },
  3396.  
  3397. _applyFreeFlowStyleTextEdit: function(now)
  3398. {
  3399. if (this._applyFreeFlowStyleTextEditTimer)
  3400. clearTimeout(this._applyFreeFlowStyleTextEditTimer);
  3401.  
  3402. function apply()
  3403. {
  3404. var valueText = this.valueElement.textContent;
  3405. if (valueText.indexOf(";") === -1)
  3406. this.applyStyleText(this.nameElement.textContent + ": " + valueText, false, false, false);
  3407. }
  3408. if (now)
  3409. apply.call(this);
  3410. else
  3411. this._applyFreeFlowStyleTextEditTimer = setTimeout(apply.bind(this), 100);
  3412. },
  3413.  
  3414. kickFreeFlowStyleEditForTest: function()
  3415. {
  3416. this._applyFreeFlowStyleTextEdit(true);
  3417. },
  3418.  
  3419. editingEnded: function(context)
  3420. {
  3421. this._resetMouseDownElement();
  3422. if (this._applyFreeFlowStyleTextEditTimer)
  3423. clearTimeout(this._applyFreeFlowStyleTextEditTimer);
  3424.  
  3425. this.hasChildren = context.hasChildren;
  3426. if (context.expanded)
  3427. this.expand();
  3428. var editedElement = context.isEditingName ? this.nameElement : this.valueElement;
  3429.  
  3430. if (editedElement.parentElement)
  3431. editedElement.parentElement.removeStyleClass("child-editing");
  3432.  
  3433. delete this._parentPane._isEditingStyle;
  3434. },
  3435.  
  3436. editingCancelled: function(element, context)
  3437. {
  3438. this._removePrompt();
  3439. this._revertStyleUponEditingCanceled(this.originalPropertyText);
  3440.  
  3441. this.editingEnded(context);
  3442. },
  3443.  
  3444. _revertStyleUponEditingCanceled: function(originalPropertyText)
  3445. {
  3446. if (typeof originalPropertyText === "string") {
  3447. delete this.originalPropertyText;
  3448. this.applyStyleText(originalPropertyText, true, false, true);
  3449. } else {
  3450. if (this._newProperty)
  3451. this.treeOutline.removeChild(this);
  3452. else
  3453. this.updateTitle();
  3454. }
  3455. },
  3456.  
  3457. _findSibling: function(moveDirection)
  3458. {
  3459. var target = this;
  3460. do {
  3461. target = (moveDirection === "forward" ? target.nextSibling : target.previousSibling);
  3462. } while(target && target.inherited);
  3463.  
  3464. return target;
  3465. },
  3466.  
  3467. editingCommitted: function(element, userInput, previousContent, context, moveDirection)
  3468. {
  3469. this._removePrompt();
  3470. this.editingEnded(context);
  3471. var isEditingName = context.isEditingName;
  3472.  
  3473.  
  3474. var createNewProperty, moveToPropertyName, moveToSelector;
  3475. var moveTo = this;
  3476. var moveToOther = (isEditingName ^ (moveDirection === "forward"));
  3477. var abandonNewProperty = this._newProperty && !userInput && (moveToOther || isEditingName);
  3478. if (moveDirection === "forward" && !isEditingName || moveDirection === "backward" && isEditingName) {
  3479. moveTo = moveTo._findSibling(moveDirection);
  3480. if (moveTo)
  3481. moveToPropertyName = moveTo.name;
  3482. else if (moveDirection === "forward" && (!this._newProperty || userInput))
  3483. createNewProperty = true;
  3484. else if (moveDirection === "backward")
  3485. moveToSelector = true;
  3486. }
  3487.  
  3488.  
  3489. var moveToIndex = moveTo && this.treeOutline ? this.treeOutline.children.indexOf(moveTo) : -1;
  3490. var blankInput = /^\s*$/.test(userInput);
  3491. var isDataPasted = "originalName" in context;
  3492. var isDirtyViaPaste = isDataPasted && (this.nameElement.textContent !== context.originalName || this.valueElement.textContent !== context.originalValue);
  3493. var shouldCommitNewProperty = this._newProperty && (moveToOther || (!moveDirection && !isEditingName) || (isEditingName && blankInput));
  3494. if (((userInput !== previousContent || isDirtyViaPaste) && !this._newProperty) || shouldCommitNewProperty) {
  3495. this.treeOutline.section._afterUpdate = moveToNextCallback.bind(this, this._newProperty, !blankInput, this.treeOutline.section);
  3496. var propertyText;
  3497. if (blankInput || (this._newProperty && /^\s*$/.test(this.valueElement.textContent)))
  3498. propertyText = "";
  3499. else {
  3500. if (isEditingName)
  3501. propertyText = userInput + ": " + this.valueElement.textContent;
  3502. else
  3503. propertyText = this.nameElement.textContent + ": " + userInput;
  3504. }
  3505. this.applyStyleText(propertyText, true, true, false);
  3506. } else {
  3507. if (!isDataPasted && !this._newProperty)
  3508. this.updateTitle();
  3509. moveToNextCallback.call(this, this._newProperty, false, this.treeOutline.section);
  3510. }
  3511.  
  3512.  
  3513. function moveToNextCallback(alreadyNew, valueChanged, section)
  3514. {
  3515. if (!moveDirection)
  3516. return;
  3517.  
  3518.  
  3519. if (moveTo && moveTo.parent) {
  3520. moveTo.startEditing(!isEditingName ? moveTo.nameElement : moveTo.valueElement);
  3521. return;
  3522. }
  3523.  
  3524.  
  3525.  
  3526. if (moveTo && !moveTo.parent) {
  3527. var propertyElements = section.propertiesTreeOutline.children;
  3528. if (moveDirection === "forward" && blankInput && !isEditingName)
  3529. --moveToIndex;
  3530. if (moveToIndex >= propertyElements.length && !this._newProperty)
  3531. createNewProperty = true;
  3532. else {
  3533. var treeElement = moveToIndex >= 0 ? propertyElements[moveToIndex] : null;
  3534. if (treeElement) {
  3535. var elementToEdit = !isEditingName ? treeElement.nameElement : treeElement.valueElement;
  3536. if (alreadyNew && blankInput)
  3537. elementToEdit = moveDirection === "forward" ? treeElement.nameElement : treeElement.valueElement;
  3538. treeElement.startEditing(elementToEdit);
  3539. return;
  3540. } else if (!alreadyNew)
  3541. moveToSelector = true;
  3542. }
  3543. }
  3544.  
  3545.  
  3546. if (createNewProperty) {
  3547. if (alreadyNew && !valueChanged && (isEditingName ^ (moveDirection === "backward")))
  3548. return;
  3549.  
  3550. section.addNewBlankProperty().startEditing();
  3551. return;
  3552. }
  3553.  
  3554. if (abandonNewProperty) {
  3555. moveTo = this._findSibling(moveDirection);
  3556. var sectionToEdit = (moveTo || moveDirection === "backward") ? section : section.nextEditableSibling();
  3557. if (sectionToEdit) {
  3558. if (sectionToEdit.rule)
  3559. sectionToEdit.startEditingSelector();
  3560. else
  3561. sectionToEdit._moveEditorFromSelector(moveDirection);
  3562. }
  3563. return;
  3564. }
  3565.  
  3566. if (moveToSelector) {
  3567. if (section.rule)
  3568. section.startEditingSelector();
  3569. else
  3570. section._moveEditorFromSelector(moveDirection);
  3571. }
  3572. }
  3573. },
  3574.  
  3575. _removePrompt: function()
  3576. {
  3577.  
  3578. if (this._prompt) {
  3579. this._prompt.detach();
  3580. delete this._prompt;
  3581. }
  3582. },
  3583.  
  3584. _hasBeenModifiedIncrementally: function()
  3585. {
  3586.  
  3587.  
  3588. return typeof this.originalPropertyText === "string" || (!!this.property.propertyText && this._newProperty);
  3589. },
  3590.  
  3591. applyStyleText: function(styleText, updateInterface, majorChange, isRevert)
  3592. {
  3593. function userOperationFinishedCallback(parentPane, updateInterface)
  3594. {
  3595. if (updateInterface)
  3596. delete parentPane._userOperation;
  3597. }
  3598.  
  3599.  
  3600. if (!isRevert && !updateInterface && !this._hasBeenModifiedIncrementally()) {
  3601.  
  3602.  
  3603. this.originalPropertyText = this.property.propertyText;
  3604. }
  3605.  
  3606. if (!this.treeOutline)
  3607. return;
  3608.  
  3609. var section = this.treeOutline.section;
  3610. styleText = styleText.replace(/\s/g, " ").trim(); 
  3611. var styleTextLength = styleText.length;
  3612. if (!styleTextLength && updateInterface && !isRevert && this._newProperty && !this._hasBeenModifiedIncrementally()) {
  3613.  
  3614. this.parent.removeChild(this);
  3615. section.afterUpdate();
  3616. return;
  3617. }
  3618.  
  3619. var currentNode = this._parentPane.node;
  3620. if (updateInterface)
  3621. this._parentPane._userOperation = true;
  3622.  
  3623. function callback(userCallback, originalPropertyText, newStyle)
  3624. {
  3625. if (!newStyle) {
  3626. if (updateInterface) {
  3627.  
  3628. this._revertStyleUponEditingCanceled(originalPropertyText);
  3629. }
  3630. userCallback();
  3631. return;
  3632. }
  3633.  
  3634. if (this._newProperty)
  3635. this._newPropertyInStyle = true;
  3636. this.style = newStyle;
  3637. this.property = newStyle.propertyAt(this.property.index);
  3638. this._styleRule.style = this.style;
  3639.  
  3640. if (section && section.pane)
  3641. section.pane.dispatchEventToListeners("style edited");
  3642.  
  3643. if (updateInterface && currentNode === section.pane.node) {
  3644. this._updatePane(userCallback);
  3645. return;
  3646. }
  3647.  
  3648. userCallback();
  3649. }
  3650.  
  3651.  
  3652.  
  3653. if (styleText.length && !/;\s*$/.test(styleText))
  3654. styleText += ";";
  3655. var overwriteProperty = !!(!this._newProperty || this._newPropertyInStyle);
  3656. this.property.setText(styleText, majorChange, overwriteProperty, callback.bind(this, userOperationFinishedCallback.bind(null, this._parentPane, updateInterface), this.originalPropertyText));
  3657. },
  3658.  
  3659. ondblclick: function()
  3660. {
  3661. return true; 
  3662. },
  3663.  
  3664. isEventWithinDisclosureTriangle: function(event)
  3665. {
  3666. if (!this.section.computedStyle)
  3667. return event.target === this._expandElement;
  3668. return TreeElement.prototype.isEventWithinDisclosureTriangle.call(this, event);
  3669. },
  3670.  
  3671. __proto__: TreeElement.prototype
  3672. }
  3673.  
  3674.  
  3675. WebInspector.StylesSidebarPane.CSSPropertyPrompt = function(cssCompletions, sidebarPane, isEditingName, acceptCallback)
  3676. {
  3677.  
  3678. WebInspector.TextPrompt.call(this, this._buildPropertyCompletions.bind(this), WebInspector.StyleValueDelimiters);
  3679. this.setSuggestBoxEnabled("generic-suggest");
  3680. this._cssCompletions = cssCompletions;
  3681. this._sidebarPane = sidebarPane;
  3682. this._isEditingName = isEditingName;
  3683. }
  3684.  
  3685. WebInspector.StylesSidebarPane.CSSPropertyPrompt.prototype = {
  3686. onKeyDown: function(event)
  3687. {
  3688. switch (event.keyIdentifier) {
  3689. case "Up":
  3690. case "Down":
  3691. case "PageUp":
  3692. case "PageDown":
  3693. if (this._handleNameOrValueUpDown(event)) {
  3694. event.preventDefault();
  3695. return;
  3696. }
  3697. break;
  3698. }
  3699.  
  3700. WebInspector.TextPrompt.prototype.onKeyDown.call(this, event);
  3701. },
  3702.  
  3703. onMouseWheel: function(event)
  3704. {
  3705. if (this._handleNameOrValueUpDown(event)) {
  3706. event.consume(true);
  3707. return;
  3708. }
  3709. WebInspector.TextPrompt.prototype.onMouseWheel.call(this, event);
  3710. },
  3711.  
  3712. tabKeyPressed: function()
  3713. {
  3714. this.acceptAutoComplete();
  3715.  
  3716.  
  3717. return false;
  3718. },
  3719.  
  3720. _handleNameOrValueUpDown: function(event)
  3721. {
  3722. function finishHandler(originalValue, replacementString)
  3723. {
  3724.  
  3725. this._sidebarPane.applyStyleText(this._sidebarPane.nameElement.textContent + ": " + this._sidebarPane.valueElement.textContent, false, false, false);
  3726. }
  3727.  
  3728.  
  3729. if (!this._isEditingName && WebInspector.handleElementValueModifications(event, this._sidebarPane.valueElement, finishHandler.bind(this), this._isValueSuggestion.bind(this)))
  3730. return true;
  3731.  
  3732. return false;
  3733. },
  3734.  
  3735. _isValueSuggestion: function(word)
  3736. {
  3737. if (!word)
  3738. return false;
  3739. word = word.toLowerCase();
  3740. return this._cssCompletions.keySet().hasOwnProperty(word);
  3741. },
  3742.  
  3743.  
  3744. _buildPropertyCompletions: function(proxyElement, wordRange, force, completionsReadyCallback)
  3745. {
  3746. var prefix = wordRange.toString().toLowerCase();
  3747. if (!prefix && !force)
  3748. return;
  3749.  
  3750. var results = this._cssCompletions.startsWith(prefix);
  3751. var selectedIndex = this._cssCompletions.mostUsedOf(results);
  3752. completionsReadyCallback(results, selectedIndex);
  3753. },
  3754.  
  3755. __proto__: WebInspector.TextPrompt.prototype
  3756. }
  3757. ;
  3758.  
  3759.  
  3760. WebInspector.ElementsPanel = function()
  3761. {
  3762. WebInspector.Panel.call(this, "elements");
  3763. this.registerRequiredCSS("breadcrumbList.css");
  3764. this.registerRequiredCSS("elementsPanel.css");
  3765. this.registerRequiredCSS("textPrompt.css");
  3766. this.setHideOnDetach();
  3767.  
  3768. const initialSidebarWidth = 325;
  3769. const minimumContentWidthPercent = 34;
  3770. this.createSidebarView(this.element, WebInspector.SidebarView.SidebarPosition.Right, initialSidebarWidth);
  3771. this.splitView.setMinimumSidebarWidth(Preferences.minElementsSidebarWidth);
  3772. this.splitView.setMinimumMainWidthPercent(minimumContentWidthPercent);
  3773.  
  3774. this.contentElement = this.splitView.mainElement;
  3775. this.contentElement.id = "elements-content";
  3776. this.contentElement.addStyleClass("outline-disclosure");
  3777. this.contentElement.addStyleClass("source-code");
  3778. if (!WebInspector.settings.domWordWrap.get())
  3779. this.contentElement.classList.add("nowrap");
  3780. WebInspector.settings.domWordWrap.addChangeListener(this._domWordWrapSettingChanged.bind(this));
  3781.  
  3782. this.contentElement.addEventListener("contextmenu", this._contextMenuEventFired.bind(this), true);
  3783.  
  3784. this.treeOutline = new WebInspector.ElementsTreeOutline(true, true, false, this._populateContextMenu.bind(this), this._setPseudoClassForNodeId.bind(this));
  3785. this.treeOutline.wireToDomAgent();
  3786.  
  3787. this.treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged, this._selectedNodeChanged, this);
  3788.  
  3789. this.crumbsElement = document.createElement("div");
  3790. this.crumbsElement.className = "crumbs";
  3791. this.crumbsElement.addEventListener("mousemove", this._mouseMovedInCrumbs.bind(this), false);
  3792. this.crumbsElement.addEventListener("mouseout", this._mouseMovedOutOfCrumbs.bind(this), false);
  3793.  
  3794. this.sidebarPanes = {};
  3795. this.sidebarPanes.computedStyle = new WebInspector.ComputedStyleSidebarPane();
  3796. this.sidebarPanes.styles = new WebInspector.StylesSidebarPane(this.sidebarPanes.computedStyle, this._setPseudoClassForNodeId.bind(this));
  3797. this.sidebarPanes.metrics = new WebInspector.MetricsSidebarPane();
  3798. this.sidebarPanes.properties = new WebInspector.PropertiesSidebarPane();
  3799. this.sidebarPanes.domBreakpoints = WebInspector.domBreakpointsSidebarPane;
  3800. this.sidebarPanes.eventListeners = new WebInspector.EventListenersSidebarPane();
  3801.  
  3802. this.sidebarPanes.styles.onexpand = this.updateStyles.bind(this);
  3803. this.sidebarPanes.metrics.onexpand = this.updateMetrics.bind(this);
  3804. this.sidebarPanes.properties.onexpand = this.updateProperties.bind(this);
  3805. this.sidebarPanes.eventListeners.onexpand = this.updateEventListeners.bind(this);
  3806.  
  3807. this.sidebarPanes.styles.expanded = true;
  3808.  
  3809. this.sidebarPanes.styles.addEventListener("style edited", this._stylesPaneEdited, this);
  3810. this.sidebarPanes.styles.addEventListener("style property toggled", this._stylesPaneEdited, this);
  3811. this.sidebarPanes.metrics.addEventListener("metrics edited", this._metricsPaneEdited, this);
  3812.  
  3813. for (var pane in this.sidebarPanes) {
  3814. this.sidebarElement.appendChild(this.sidebarPanes[pane].element);
  3815. if (this.sidebarPanes[pane].onattach)
  3816. this.sidebarPanes[pane].onattach();
  3817. }
  3818.  
  3819. this._popoverHelper = new WebInspector.PopoverHelper(this.element, this._getPopoverAnchor.bind(this), this._showPopover.bind(this));
  3820. this._popoverHelper.setTimeout(0);
  3821.  
  3822. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, this._updateBreadcrumbIfNeeded, this);
  3823. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrRemoved, this._updateBreadcrumbIfNeeded, this);
  3824. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.NodeRemoved, this._nodeRemoved, this);
  3825. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.DocumentUpdated, this._documentUpdatedEvent, this);
  3826. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.InspectElementRequested, this._inspectElementRequested, this);
  3827.  
  3828. if (WebInspector.domAgent.existingDocument())
  3829. this._documentUpdated(WebInspector.domAgent.existingDocument());
  3830. }
  3831.  
  3832. WebInspector.ElementsPanel.prototype = {
  3833. get statusBarItems()
  3834. {
  3835. return [this.crumbsElement];
  3836. },
  3837.  
  3838. defaultFocusedElement: function()
  3839. {
  3840. return this.treeOutline.element;
  3841. },
  3842.  
  3843. statusBarResized: function()
  3844. {
  3845. this.updateBreadcrumbSizes();
  3846. },
  3847.  
  3848. wasShown: function()
  3849. {
  3850.  
  3851. if (this.treeOutline.element.parentElement !== this.contentElement)
  3852. this.contentElement.appendChild(this.treeOutline.element);
  3853.  
  3854. WebInspector.Panel.prototype.wasShown.call(this);
  3855.  
  3856. this.updateBreadcrumb();
  3857. this.treeOutline.updateSelection();
  3858. this.treeOutline.setVisible(true);
  3859.  
  3860. if (!this.treeOutline.rootDOMNode)
  3861. WebInspector.domAgent.requestDocument();
  3862.  
  3863. this.sidebarElement.insertBefore(this.sidebarPanes.domBreakpoints.element, this.sidebarPanes.eventListeners.element);
  3864. },
  3865.  
  3866. willHide: function()
  3867. {
  3868. WebInspector.domAgent.hideDOMNodeHighlight();
  3869. this.treeOutline.setVisible(false);
  3870. this._popoverHelper.hidePopover();
  3871.  
  3872.  
  3873. this.contentElement.removeChild(this.treeOutline.element);
  3874.  
  3875. for (var pane in this.sidebarPanes) {
  3876. if (this.sidebarPanes[pane].willHide)
  3877. this.sidebarPanes[pane].willHide();
  3878. }
  3879.  
  3880. WebInspector.Panel.prototype.willHide.call(this);
  3881. },
  3882.  
  3883. onResize: function()
  3884. {
  3885. this.treeOutline.updateSelection();
  3886. this.updateBreadcrumbSizes();
  3887. },
  3888.  
  3889.  
  3890. _setPseudoClassForNodeId: function(nodeId, pseudoClass, enable)
  3891. {
  3892. var node = WebInspector.domAgent.nodeForId(nodeId);
  3893. if (!node)
  3894. return;
  3895.  
  3896. var pseudoClasses = node.getUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName);
  3897. if (enable) {
  3898. pseudoClasses = pseudoClasses || [];
  3899. if (pseudoClasses.indexOf(pseudoClass) >= 0)
  3900. return;
  3901. pseudoClasses.push(pseudoClass);
  3902. node.setUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName, pseudoClasses);
  3903. } else {
  3904. if (!pseudoClasses || pseudoClasses.indexOf(pseudoClass) < 0)
  3905. return;
  3906. pseudoClasses.remove(pseudoClass);
  3907. if (!pseudoClasses.length)
  3908. node.removeUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName);
  3909. }
  3910.  
  3911. this.treeOutline.updateOpenCloseTags(node);
  3912. WebInspector.cssModel.forcePseudoState(node.id, node.getUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName));
  3913. this._metricsPaneEdited();
  3914. this._stylesPaneEdited();
  3915.  
  3916. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  3917. action: WebInspector.UserMetrics.UserActionNames.ForcedElementState,
  3918. selector: node.appropriateSelectorFor(false),
  3919. enabled: enable,
  3920. state: pseudoClass
  3921. });
  3922. },
  3923.  
  3924. _selectedNodeChanged: function()
  3925. {
  3926. var selectedNode = this.selectedDOMNode();
  3927. if (!selectedNode && this._lastValidSelectedNode)
  3928. this._selectedPathOnReset = this._lastValidSelectedNode.path();
  3929.  
  3930. this.updateBreadcrumb(false);
  3931.  
  3932. this._updateSidebars();
  3933.  
  3934. if (selectedNode) {
  3935. ConsoleAgent.addInspectedNode(selectedNode.id);
  3936. this._lastValidSelectedNode = selectedNode;
  3937. }
  3938. WebInspector.notifications.dispatchEventToListeners(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged);
  3939. },
  3940.  
  3941. _updateSidebars: function()
  3942. {
  3943. for (var pane in this.sidebarPanes)
  3944. this.sidebarPanes[pane].needsUpdate = true;
  3945.  
  3946. this.updateStyles(true);
  3947. this.updateMetrics();
  3948. this.updateProperties();
  3949. this.updateEventListeners();
  3950. },
  3951.  
  3952. _reset: function()
  3953. {
  3954. delete this.currentQuery;
  3955. },
  3956.  
  3957. _documentUpdatedEvent: function(event)
  3958. {
  3959. this._documentUpdated(event.data);
  3960. },
  3961.  
  3962. _documentUpdated: function(inspectedRootDocument)
  3963. {
  3964. this._reset();
  3965. this.searchCanceled();
  3966.  
  3967. this.treeOutline.rootDOMNode = inspectedRootDocument;
  3968.  
  3969. if (!inspectedRootDocument) {
  3970. if (this.isShowing())
  3971. WebInspector.domAgent.requestDocument();
  3972. return;
  3973. }
  3974.  
  3975. this.sidebarPanes.domBreakpoints.restoreBreakpoints();
  3976.  
  3977.  
  3978. function selectNode(candidateFocusNode)
  3979. {
  3980. if (!candidateFocusNode)
  3981. candidateFocusNode = inspectedRootDocument.body || inspectedRootDocument.documentElement;
  3982.  
  3983. if (!candidateFocusNode)
  3984. return;
  3985.  
  3986. this.selectDOMNode(candidateFocusNode);
  3987. if (this.treeOutline.selectedTreeElement)
  3988. this.treeOutline.selectedTreeElement.expand();
  3989. }
  3990.  
  3991. function selectLastSelectedNode(nodeId)
  3992. {
  3993. if (this.selectedDOMNode()) {
  3994.  
  3995. return;
  3996. }
  3997. var node = nodeId ? WebInspector.domAgent.nodeForId(nodeId) : null;
  3998. selectNode.call(this, node);
  3999. }
  4000.  
  4001. if (this._selectedPathOnReset)
  4002. WebInspector.domAgent.pushNodeByPathToFrontend(this._selectedPathOnReset, selectLastSelectedNode.bind(this));
  4003. else
  4004. selectNode.call(this);
  4005. delete this._selectedPathOnReset;
  4006. },
  4007.  
  4008. searchCanceled: function()
  4009. {
  4010. delete this._searchQuery;
  4011. this._hideSearchHighlights();
  4012.  
  4013. WebInspector.searchController.updateSearchMatchesCount(0, this);
  4014.  
  4015. delete this._currentSearchResultIndex;
  4016. delete this._searchResults;
  4017. WebInspector.domAgent.cancelSearch();
  4018. },
  4019.  
  4020.  
  4021. performSearch: function(query)
  4022. {
  4023.  
  4024. this.searchCanceled();
  4025.  
  4026. const whitespaceTrimmedQuery = query.trim();
  4027. if (!whitespaceTrimmedQuery.length)
  4028. return;
  4029.  
  4030. this._searchQuery = query;
  4031.  
  4032.  
  4033. function resultCountCallback(resultCount)
  4034. {
  4035. WebInspector.searchController.updateSearchMatchesCount(resultCount, this);
  4036. if (!resultCount)
  4037. return;
  4038.  
  4039. this._searchResults = new Array(resultCount);
  4040. this._currentSearchResultIndex = -1;
  4041. this.jumpToNextSearchResult();
  4042. }
  4043. WebInspector.domAgent.performSearch(whitespaceTrimmedQuery, resultCountCallback.bind(this));
  4044. },
  4045.  
  4046. _contextMenuEventFired: function(event)
  4047. {
  4048. function toggleWordWrap()
  4049. {
  4050. WebInspector.settings.domWordWrap.set(!WebInspector.settings.domWordWrap.get());
  4051. }
  4052.  
  4053. var contextMenu = new WebInspector.ContextMenu(event);
  4054. var populated = this.treeOutline.populateContextMenu(contextMenu, event);
  4055.  
  4056. if (WebInspector.experimentsSettings.cssRegions.isEnabled()) {
  4057. contextMenu.appendSeparator();
  4058. contextMenu.appendItem(WebInspector.UIString("CSS Named Flows..."), this._showNamedFlowCollections.bind(this));
  4059. }
  4060.  
  4061. contextMenu.appendSeparator();
  4062. contextMenu.appendCheckboxItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Word wrap" : "Word Wrap"), toggleWordWrap.bind(this), WebInspector.settings.domWordWrap.get());
  4063.  
  4064. contextMenu.show();
  4065. },
  4066.  
  4067. _showNamedFlowCollections: function()
  4068. {
  4069. if (!WebInspector.cssNamedFlowCollectionsView)
  4070. WebInspector.cssNamedFlowCollectionsView = new WebInspector.CSSNamedFlowCollectionsView();
  4071. WebInspector.cssNamedFlowCollectionsView.showInDrawer();
  4072. },
  4073.  
  4074. _domWordWrapSettingChanged: function(event)
  4075. {
  4076. if (event.data)
  4077. this.contentElement.removeStyleClass("nowrap");
  4078. else
  4079. this.contentElement.addStyleClass("nowrap");
  4080.  
  4081. var selectedNode = this.selectedDOMNode();
  4082. if (!selectedNode)
  4083. return;
  4084.  
  4085. var treeElement = this.treeOutline.findTreeElement(selectedNode);
  4086. if (treeElement)
  4087. treeElement.updateSelection(); 
  4088. },
  4089.  
  4090. switchToAndFocus: function(node)
  4091. {
  4092.  
  4093. WebInspector.searchController.cancelSearch();
  4094. WebInspector.inspectorView.setCurrentPanel(this);
  4095. this.selectDOMNode(node, true);
  4096. },
  4097.  
  4098. _populateContextMenu: function(contextMenu, node)
  4099. {
  4100.  
  4101. contextMenu.appendSeparator();
  4102. var pane = this.sidebarPanes.domBreakpoints;
  4103. pane.populateNodeContextMenu(node, contextMenu);
  4104. },
  4105.  
  4106. _getPopoverAnchor: function(element)
  4107. {
  4108. var anchor = element.enclosingNodeOrSelfWithClass("webkit-html-resource-link");
  4109. if (anchor) {
  4110. if (!anchor.href)
  4111. return null;
  4112.  
  4113. var resource = WebInspector.resourceTreeModel.resourceForURL(anchor.href);
  4114. if (!resource || resource.type !== WebInspector.resourceTypes.Image)
  4115. return null;
  4116.  
  4117. anchor.removeAttribute("title");
  4118. }
  4119. return anchor;
  4120. },
  4121.  
  4122. _loadDimensionsForNode: function(treeElement, callback)
  4123. {
  4124.  
  4125. if (treeElement.treeOutline !== this.treeOutline) {
  4126. callback();
  4127. return;
  4128. }
  4129.  
  4130. var node =   (treeElement.representedObject);
  4131.  
  4132. if (!node.nodeName() || node.nodeName().toLowerCase() !== "img") {
  4133. callback();
  4134. return;
  4135. }
  4136.  
  4137. WebInspector.RemoteObject.resolveNode(node, "", resolvedNode);
  4138.  
  4139. function resolvedNode(object)
  4140. {
  4141. if (!object) {
  4142. callback();
  4143. return;
  4144. }
  4145.  
  4146. object.callFunctionJSON(dimensions, undefined, callback);
  4147. object.release();
  4148.  
  4149. function dimensions()
  4150. {
  4151. return { offsetWidth: this.offsetWidth, offsetHeight: this.offsetHeight, naturalWidth: this.naturalWidth, naturalHeight: this.naturalHeight };
  4152. }
  4153. }
  4154. },
  4155.  
  4156.  
  4157. _showPopover: function(anchor, popover)
  4158. {
  4159. var listItem = anchor.enclosingNodeOrSelfWithNodeName("li");
  4160. if (listItem && listItem.treeElement)
  4161. this._loadDimensionsForNode(listItem.treeElement, WebInspector.DOMPresentationUtils.buildImagePreviewContents.bind(WebInspector.DOMPresentationUtils, anchor.href, true, showPopover));
  4162. else
  4163. WebInspector.DOMPresentationUtils.buildImagePreviewContents(anchor.href, true, showPopover);
  4164.  
  4165.  
  4166. function showPopover(contents)
  4167. {
  4168. if (!contents)
  4169. return;
  4170. popover.setCanShrink(false);
  4171. popover.show(contents, anchor);
  4172. }
  4173. },
  4174.  
  4175. jumpToNextSearchResult: function()
  4176. {
  4177. if (!this._searchResults)
  4178. return;
  4179.  
  4180. this._hideSearchHighlights();
  4181. if (++this._currentSearchResultIndex >= this._searchResults.length)
  4182. this._currentSearchResultIndex = 0;
  4183.  
  4184. this._highlightCurrentSearchResult();
  4185. },
  4186.  
  4187. jumpToPreviousSearchResult: function()
  4188. {
  4189. if (!this._searchResults)
  4190. return;
  4191.  
  4192. this._hideSearchHighlights();
  4193. if (--this._currentSearchResultIndex < 0)
  4194. this._currentSearchResultIndex = (this._searchResults.length - 1);
  4195.  
  4196. this._highlightCurrentSearchResult();
  4197. return true;
  4198. },
  4199.  
  4200. _highlightCurrentSearchResult: function()
  4201. {
  4202. var index = this._currentSearchResultIndex;
  4203. var searchResults = this._searchResults;
  4204. var searchResult = searchResults[index];
  4205.  
  4206. if (searchResult === null) {
  4207. WebInspector.searchController.updateCurrentMatchIndex(index, this);
  4208. return;
  4209. }
  4210.  
  4211. if (typeof searchResult === "undefined") {
  4212.  
  4213. function callback(node)
  4214. {
  4215. searchResults[index] = node || null;
  4216. this._highlightCurrentSearchResult();
  4217. }
  4218. WebInspector.domAgent.searchResult(index, callback.bind(this));
  4219. return;
  4220. }
  4221.  
  4222. WebInspector.searchController.updateCurrentMatchIndex(index, this);
  4223.  
  4224. var treeElement = this.treeOutline.findTreeElement(searchResult);
  4225. if (treeElement) {
  4226. treeElement.highlightSearchResults(this._searchQuery);
  4227. treeElement.reveal();
  4228. }
  4229. },
  4230.  
  4231. _hideSearchHighlights: function()
  4232. {
  4233. if (!this._searchResults)
  4234. return;
  4235. var searchResult = this._searchResults[this._currentSearchResultIndex];
  4236. if (!searchResult)
  4237. return;
  4238. var treeElement = this.treeOutline.findTreeElement(searchResult);
  4239. if (treeElement)
  4240. treeElement.hideSearchHighlights();
  4241. },
  4242.  
  4243. selectedDOMNode: function()
  4244. {
  4245. return this.treeOutline.selectedDOMNode();
  4246. },
  4247.  
  4248.  
  4249. selectDOMNode: function(node, focus)
  4250. {
  4251. this.treeOutline.selectDOMNode(node, focus);
  4252. },
  4253.  
  4254. _nodeRemoved: function(event)
  4255. {
  4256. if (!this.isShowing())
  4257. return;
  4258.  
  4259. var crumbs = this.crumbsElement;
  4260. for (var crumb = crumbs.firstChild; crumb; crumb = crumb.nextSibling) {
  4261. if (crumb.representedObject === event.data.node) {
  4262. this.updateBreadcrumb(true);
  4263. return;
  4264. }
  4265. }
  4266. },
  4267.  
  4268. _stylesPaneEdited: function()
  4269. {
  4270.  
  4271. this.sidebarPanes.metrics.needsUpdate = true;
  4272. this.updateMetrics();
  4273. },
  4274.  
  4275. _metricsPaneEdited: function()
  4276. {
  4277.  
  4278. this.sidebarPanes.styles.needsUpdate = true;
  4279. this.updateStyles(true);
  4280. },
  4281.  
  4282. _mouseMovedInCrumbs: function(event)
  4283. {
  4284. var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY);
  4285. var crumbElement = nodeUnderMouse.enclosingNodeOrSelfWithClass("crumb");
  4286.  
  4287. WebInspector.domAgent.highlightDOMNode(crumbElement ? crumbElement.representedObject.id : 0);
  4288.  
  4289. if ("_mouseOutOfCrumbsTimeout" in this) {
  4290. clearTimeout(this._mouseOutOfCrumbsTimeout);
  4291. delete this._mouseOutOfCrumbsTimeout;
  4292. }
  4293. },
  4294.  
  4295. _mouseMovedOutOfCrumbs: function(event)
  4296. {
  4297. var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY);
  4298. if (nodeUnderMouse && nodeUnderMouse.isDescendant(this.crumbsElement))
  4299. return;
  4300.  
  4301. WebInspector.domAgent.hideDOMNodeHighlight();
  4302.  
  4303. this._mouseOutOfCrumbsTimeout = setTimeout(this.updateBreadcrumbSizes.bind(this), 1000);
  4304. },
  4305.  
  4306. _updateBreadcrumbIfNeeded: function(event)
  4307. {
  4308. var name = event.data.name;
  4309. if (name !== "class" && name !== "id")
  4310. return;
  4311.  
  4312. var node =   (event.data.node);
  4313. var crumbs = this.crumbsElement;
  4314. var crumb = crumbs.firstChild;
  4315. while (crumb) {
  4316. if (crumb.representedObject === node) {
  4317. this.updateBreadcrumb(true);
  4318. break;
  4319. }
  4320. crumb = crumb.nextSibling;
  4321. }
  4322. },
  4323.  
  4324.  
  4325. updateBreadcrumb: function(forceUpdate)
  4326. {
  4327. if (!this.isShowing())
  4328. return;
  4329.  
  4330. var crumbs = this.crumbsElement;
  4331.  
  4332. var handled = false;
  4333. var crumb = crumbs.firstChild;
  4334. while (crumb) {
  4335. if (crumb.representedObject === this.selectedDOMNode()) {
  4336. crumb.addStyleClass("selected");
  4337. handled = true;
  4338. } else {
  4339. crumb.removeStyleClass("selected");
  4340. }
  4341.  
  4342. crumb = crumb.nextSibling;
  4343. }
  4344.  
  4345. if (handled && !forceUpdate) {
  4346.  
  4347.  
  4348. this.updateBreadcrumbSizes();
  4349. return;
  4350. }
  4351.  
  4352. crumbs.removeChildren();
  4353.  
  4354. var panel = this;
  4355.  
  4356. function selectCrumbFunction(event)
  4357. {
  4358. var crumb = event.currentTarget;
  4359. if (crumb.hasStyleClass("collapsed")) {
  4360.  
  4361. if (crumb === panel.crumbsElement.firstChild) {
  4362.  
  4363.  
  4364. var currentCrumb = crumb;
  4365. while (currentCrumb) {
  4366. var hidden = currentCrumb.hasStyleClass("hidden");
  4367. var collapsed = currentCrumb.hasStyleClass("collapsed");
  4368. if (!hidden && !collapsed)
  4369. break;
  4370. crumb = currentCrumb;
  4371. currentCrumb = currentCrumb.nextSibling;
  4372. }
  4373. }
  4374.  
  4375. panel.updateBreadcrumbSizes(crumb);
  4376. } else
  4377. panel.selectDOMNode(crumb.representedObject, true);
  4378.  
  4379. event.preventDefault();
  4380. }
  4381.  
  4382. for (var current = this.selectedDOMNode(); current; current = current.parentNode) {
  4383. if (current.nodeType() === Node.DOCUMENT_NODE)
  4384. continue;
  4385.  
  4386. crumb = document.createElement("span");
  4387. crumb.className = "crumb";
  4388. crumb.representedObject = current;
  4389. crumb.addEventListener("mousedown", selectCrumbFunction, false);
  4390.  
  4391. var crumbTitle;
  4392. switch (current.nodeType()) {
  4393. case Node.ELEMENT_NODE:
  4394. WebInspector.DOMPresentationUtils.decorateNodeLabel(current, crumb);
  4395. break;
  4396.  
  4397. case Node.TEXT_NODE:
  4398. crumbTitle = WebInspector.UIString("(text)");
  4399. break
  4400.  
  4401. case Node.COMMENT_NODE:
  4402. crumbTitle = "<!-->";
  4403. break;
  4404.  
  4405. case Node.DOCUMENT_TYPE_NODE:
  4406. crumbTitle = "<!DOCTYPE>";
  4407. break;
  4408.  
  4409. default:
  4410. crumbTitle = current.nodeNameInCorrectCase();
  4411. }
  4412.  
  4413. if (!crumb.childNodes.length) {
  4414. var nameElement = document.createElement("span");
  4415. nameElement.textContent = crumbTitle;
  4416. crumb.appendChild(nameElement);
  4417. crumb.title = crumbTitle;
  4418. }
  4419.  
  4420. if (current === this.selectedDOMNode())
  4421. crumb.addStyleClass("selected");
  4422. if (!crumbs.childNodes.length)
  4423. crumb.addStyleClass("end");
  4424.  
  4425. crumbs.appendChild(crumb);
  4426. }
  4427.  
  4428. if (crumbs.hasChildNodes())
  4429. crumbs.lastChild.addStyleClass("start");
  4430.  
  4431. this.updateBreadcrumbSizes();
  4432. },
  4433.  
  4434.  
  4435. updateBreadcrumbSizes: function(focusedCrumb)
  4436. {
  4437. if (!this.isShowing())
  4438. return;
  4439.  
  4440. if (document.body.offsetWidth <= 0) {
  4441.  
  4442.  
  4443. return;
  4444. }
  4445.  
  4446. var crumbs = this.crumbsElement;
  4447. if (!crumbs.childNodes.length || crumbs.offsetWidth <= 0)
  4448. return; 
  4449.  
  4450.  
  4451. var selectedIndex = 0;
  4452. var focusedIndex = 0;
  4453. var selectedCrumb;
  4454.  
  4455. var i = 0;
  4456. var crumb = crumbs.firstChild;
  4457. while (crumb) {
  4458.  
  4459. if (!selectedCrumb && crumb.hasStyleClass("selected")) {
  4460. selectedCrumb = crumb;
  4461. selectedIndex = i;
  4462. }
  4463.  
  4464.  
  4465. if (crumb === focusedCrumb)
  4466. focusedIndex = i;
  4467.  
  4468.  
  4469.  
  4470. if (crumb !== crumbs.lastChild)
  4471. crumb.removeStyleClass("start");
  4472. if (crumb !== crumbs.firstChild)
  4473. crumb.removeStyleClass("end");
  4474.  
  4475. crumb.removeStyleClass("compact");
  4476. crumb.removeStyleClass("collapsed");
  4477. crumb.removeStyleClass("hidden");
  4478.  
  4479. crumb = crumb.nextSibling;
  4480. ++i;
  4481. }
  4482.  
  4483.  
  4484.  
  4485. crumbs.firstChild.addStyleClass("end");
  4486. crumbs.lastChild.addStyleClass("start");
  4487.  
  4488. function crumbsAreSmallerThanContainer()
  4489. {
  4490. var rightPadding = 20;
  4491. var errorWarningElement = document.getElementById("error-warning-count");
  4492. if (!WebInspector.drawer.visible && errorWarningElement)
  4493. rightPadding += errorWarningElement.offsetWidth;
  4494. return ((crumbs.totalOffsetLeft() + crumbs.offsetWidth + rightPadding) < window.innerWidth);
  4495. }
  4496.  
  4497. if (crumbsAreSmallerThanContainer())
  4498. return; 
  4499.  
  4500. var BothSides = 0;
  4501. var AncestorSide = -1;
  4502. var ChildSide = 1;
  4503.  
  4504.  
  4505. function makeCrumbsSmaller(shrinkingFunction, direction, significantCrumb)
  4506. {
  4507. if (!significantCrumb)
  4508. significantCrumb = (focusedCrumb || selectedCrumb);
  4509.  
  4510. if (significantCrumb === selectedCrumb)
  4511. var significantIndex = selectedIndex;
  4512. else if (significantCrumb === focusedCrumb)
  4513. var significantIndex = focusedIndex;
  4514. else {
  4515. var significantIndex = 0;
  4516. for (var i = 0; i < crumbs.childNodes.length; ++i) {
  4517. if (crumbs.childNodes[i] === significantCrumb) {
  4518. significantIndex = i;
  4519. break;
  4520. }
  4521. }
  4522. }
  4523.  
  4524. function shrinkCrumbAtIndex(index)
  4525. {
  4526. var shrinkCrumb = crumbs.childNodes[index];
  4527. if (shrinkCrumb && shrinkCrumb !== significantCrumb)
  4528. shrinkingFunction(shrinkCrumb);
  4529. if (crumbsAreSmallerThanContainer())
  4530. return true; 
  4531. return false;
  4532. }
  4533.  
  4534.  
  4535.  
  4536. if (direction) {
  4537.  
  4538. var index = (direction > 0 ? 0 : crumbs.childNodes.length - 1);
  4539. while (index !== significantIndex) {
  4540. if (shrinkCrumbAtIndex(index))
  4541. return true;
  4542. index += (direction > 0 ? 1 : -1);
  4543. }
  4544. } else {
  4545.  
  4546.  
  4547. var startIndex = 0;
  4548. var endIndex = crumbs.childNodes.length - 1;
  4549. while (startIndex != significantIndex || endIndex != significantIndex) {
  4550. var startDistance = significantIndex - startIndex;
  4551. var endDistance = endIndex - significantIndex;
  4552. if (startDistance >= endDistance)
  4553. var index = startIndex++;
  4554. else
  4555. var index = endIndex--;
  4556. if (shrinkCrumbAtIndex(index))
  4557. return true;
  4558. }
  4559. }
  4560.  
  4561.  
  4562. return false;
  4563. }
  4564.  
  4565. function coalesceCollapsedCrumbs()
  4566. {
  4567. var crumb = crumbs.firstChild;
  4568. var collapsedRun = false;
  4569. var newStartNeeded = false;
  4570. var newEndNeeded = false;
  4571. while (crumb) {
  4572. var hidden = crumb.hasStyleClass("hidden");
  4573. if (!hidden) {
  4574. var collapsed = crumb.hasStyleClass("collapsed");
  4575. if (collapsedRun && collapsed) {
  4576. crumb.addStyleClass("hidden");
  4577. crumb.removeStyleClass("compact");
  4578. crumb.removeStyleClass("collapsed");
  4579.  
  4580. if (crumb.hasStyleClass("start")) {
  4581. crumb.removeStyleClass("start");
  4582. newStartNeeded = true;
  4583. }
  4584.  
  4585. if (crumb.hasStyleClass("end")) {
  4586. crumb.removeStyleClass("end");
  4587. newEndNeeded = true;
  4588. }
  4589.  
  4590. continue;
  4591. }
  4592.  
  4593. collapsedRun = collapsed;
  4594.  
  4595. if (newEndNeeded) {
  4596. newEndNeeded = false;
  4597. crumb.addStyleClass("end");
  4598. }
  4599. } else
  4600. collapsedRun = true;
  4601. crumb = crumb.nextSibling;
  4602. }
  4603.  
  4604. if (newStartNeeded) {
  4605. crumb = crumbs.lastChild;
  4606. while (crumb) {
  4607. if (!crumb.hasStyleClass("hidden")) {
  4608. crumb.addStyleClass("start");
  4609. break;
  4610. }
  4611. crumb = crumb.previousSibling;
  4612. }
  4613. }
  4614. }
  4615.  
  4616. function compact(crumb)
  4617. {
  4618. if (crumb.hasStyleClass("hidden"))
  4619. return;
  4620. crumb.addStyleClass("compact");
  4621. }
  4622.  
  4623. function collapse(crumb, dontCoalesce)
  4624. {
  4625. if (crumb.hasStyleClass("hidden"))
  4626. return;
  4627. crumb.addStyleClass("collapsed");
  4628. crumb.removeStyleClass("compact");
  4629. if (!dontCoalesce)
  4630. coalesceCollapsedCrumbs();
  4631. }
  4632.  
  4633. if (!focusedCrumb) {
  4634.  
  4635.  
  4636.  
  4637.  
  4638. if (makeCrumbsSmaller(compact, ChildSide))
  4639. return;
  4640.  
  4641.  
  4642. if (makeCrumbsSmaller(collapse, ChildSide))
  4643. return;
  4644. }
  4645.  
  4646.  
  4647. if (makeCrumbsSmaller(compact, (focusedCrumb ? BothSides : AncestorSide)))
  4648. return;
  4649.  
  4650.  
  4651. if (makeCrumbsSmaller(collapse, (focusedCrumb ? BothSides : AncestorSide)))
  4652. return;
  4653.  
  4654. if (!selectedCrumb)
  4655. return;
  4656.  
  4657.  
  4658. compact(selectedCrumb);
  4659. if (crumbsAreSmallerThanContainer())
  4660. return;
  4661.  
  4662.  
  4663. collapse(selectedCrumb, true);
  4664. },
  4665.  
  4666. updateStyles: function(forceUpdate)
  4667. {
  4668. var stylesSidebarPane = this.sidebarPanes.styles;
  4669. var computedStylePane = this.sidebarPanes.computedStyle;
  4670. if ((!stylesSidebarPane.expanded && !computedStylePane.expanded) || !stylesSidebarPane.needsUpdate)
  4671. return;
  4672.  
  4673. stylesSidebarPane.update(this.selectedDOMNode(), forceUpdate);
  4674. stylesSidebarPane.needsUpdate = false;
  4675. },
  4676.  
  4677. updateMetrics: function()
  4678. {
  4679. var metricsSidebarPane = this.sidebarPanes.metrics;
  4680. if (!metricsSidebarPane.expanded || !metricsSidebarPane.needsUpdate)
  4681. return;
  4682.  
  4683. metricsSidebarPane.update(this.selectedDOMNode());
  4684. metricsSidebarPane.needsUpdate = false;
  4685. },
  4686.  
  4687. updateProperties: function()
  4688. {
  4689. var propertiesSidebarPane = this.sidebarPanes.properties;
  4690. if (!propertiesSidebarPane.expanded || !propertiesSidebarPane.needsUpdate)
  4691. return;
  4692.  
  4693. propertiesSidebarPane.update(this.selectedDOMNode());
  4694. propertiesSidebarPane.needsUpdate = false;
  4695. },
  4696.  
  4697. updateEventListeners: function()
  4698. {
  4699. var eventListenersSidebarPane = this.sidebarPanes.eventListeners;
  4700. if (!eventListenersSidebarPane.expanded || !eventListenersSidebarPane.needsUpdate)
  4701. return;
  4702.  
  4703. eventListenersSidebarPane.update(this.selectedDOMNode());
  4704. eventListenersSidebarPane.needsUpdate = false;
  4705. },
  4706.  
  4707. handleShortcut: function(event)
  4708. {
  4709. if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) && !event.shiftKey && event.keyIdentifier === "U+005A") { 
  4710. WebInspector.domAgent.undo(this._updateSidebars.bind(this));
  4711. event.handled = true;
  4712. return;
  4713. }
  4714.  
  4715. var isRedoKey = WebInspector.isMac() ? event.metaKey && event.shiftKey && event.keyIdentifier === "U+005A" : 
  4716. event.ctrlKey && event.keyIdentifier === "U+0059"; 
  4717. if (isRedoKey) {
  4718. DOMAgent.redo(this._updateSidebars.bind(this));
  4719. event.handled = true;
  4720. return;
  4721. }
  4722.  
  4723. this.treeOutline.handleShortcut(event);
  4724. },
  4725.  
  4726. handleCopyEvent: function(event)
  4727. {
  4728.  
  4729. if (!window.getSelection().isCollapsed)
  4730. return;
  4731. event.clipboardData.clearData();
  4732. event.preventDefault();
  4733. this.selectedDOMNode().copyNode();
  4734. },
  4735.  
  4736. sidebarResized: function(event)
  4737. {
  4738. this.treeOutline.updateSelection();
  4739. },
  4740.  
  4741. _inspectElementRequested: function(event)
  4742. {
  4743. var node = event.data;
  4744. this.revealAndSelectNode(node.id);
  4745. },
  4746.  
  4747. revealAndSelectNode: function(nodeId)
  4748. {
  4749. WebInspector.inspectorView.setCurrentPanel(this);
  4750.  
  4751. var node = WebInspector.domAgent.nodeForId(nodeId);
  4752. if (!node)
  4753. return;
  4754.  
  4755. WebInspector.domAgent.highlightDOMNodeForTwoSeconds(nodeId);
  4756. this.selectDOMNode(node, true);
  4757. },
  4758.  
  4759.  
  4760. appendApplicableItems: function(event, contextMenu, target)
  4761. {
  4762. if (!(target instanceof WebInspector.RemoteObject))
  4763. return;
  4764. var remoteObject =   (target);
  4765. if (remoteObject.subtype !== "node")
  4766. return;
  4767.  
  4768. function selectNode(nodeId)
  4769. {
  4770. if (nodeId)
  4771. WebInspector.domAgent.inspectElement(nodeId);
  4772. }
  4773.  
  4774. function revealElement()
  4775. {
  4776. remoteObject.pushNodeToFrontend(selectNode);
  4777. }
  4778.  
  4779. contextMenu.appendItem(WebInspector.UIString("Reveal in Elements Panel"), revealElement.bind(this));
  4780. },
  4781.  
  4782. __proto__: WebInspector.Panel.prototype
  4783. }
  4784.